mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-22 12:38:53 +00:00
[TS/JS] Move TS tests to dedicated folder and deps upgrade (#7508)
* Move TS tests to dedicated folder and deps upgrade * Attempt to fix generate_code * Fix dir on CI * Add js extension * Fix missing extension * Harmonize with test gen * Unexplained code gen change * Restore yarn.lock * Naive attempt to fix bazel stuff * Pin @bazel/typescript to 5.2.0 * Attempt to fix bazel * More tweak * Upgrade deps * Tweak? * Fix path * Fix test package Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
12
tests/ts/BUILD.bazel
Normal file
12
tests/ts/BUILD.bazel
Normal file
@@ -0,0 +1,12 @@
|
||||
load("//:typescript.bzl", "flatbuffer_ts_library")
|
||||
|
||||
package(default_visibility = ["//visibility:private"])
|
||||
|
||||
flatbuffer_ts_library(
|
||||
name = "typescript_ts_fbs",
|
||||
srcs = ["typescript_keywords.fbs"],
|
||||
deps = [
|
||||
"//tests/ts/test_dir:include_ts_fbs",
|
||||
"//tests/ts/test_dir:typescript_transitive_ts_fbs",
|
||||
],
|
||||
)
|
||||
390
tests/ts/JavaScriptFlexBuffersTest.js
Normal file
390
tests/ts/JavaScriptFlexBuffersTest.js
Normal file
@@ -0,0 +1,390 @@
|
||||
// Run this using JavaScriptTest.sh
|
||||
import assert from 'assert'
|
||||
import fs from 'fs'
|
||||
import * as flexbuffers from 'flatbuffers/js/flexbuffers.js'
|
||||
|
||||
function main() {
|
||||
testSingleValueBuffers();
|
||||
testGoldBuffer();
|
||||
testEncode();
|
||||
testIndirectAdd();
|
||||
testIndirectWithCache();
|
||||
testMapBuilder();
|
||||
testRoundTrip();
|
||||
testRoundTripWithBuilder();
|
||||
testDeduplicationOff();
|
||||
testBugWhereOffestWereStoredAsIntInsteadOfUInt();
|
||||
|
||||
console.log('FlexBuffers test: completed successfully');
|
||||
}
|
||||
|
||||
function testSingleValueBuffers() {
|
||||
{
|
||||
const ref = flexbuffers.toReference(new Uint8Array([0, 0, 1]).buffer);
|
||||
assert.strictEqual(true, ref.isNull());
|
||||
}
|
||||
|
||||
function _assert(object, buffer) {
|
||||
assert.deepStrictEqual(flexbuffers.toObject(new Uint8Array(buffer).buffer), object);
|
||||
}
|
||||
_assert(true, [1, 104, 1]);
|
||||
_assert(false, [0, 104, 1]);
|
||||
_assert(25, [25, 4, 1]);
|
||||
_assert(-25, [231, 4, 1]);
|
||||
_assert(230, [230, 8, 1]);
|
||||
_assert(230, [230, 0, 5, 2]);
|
||||
_assert(-1025, [255, 251, 5, 2]);
|
||||
_assert(1025, [1, 4, 9, 2]);
|
||||
_assert(2147483647, [255, 255, 255, 127, 6, 4]);
|
||||
_assert(-2147483648, [0, 0, 0, 128, 6, 4]);
|
||||
_assert(4294967295n, [255, 255, 255, 255, 0, 0, 0, 0, 7, 8]);
|
||||
_assert(9223372036854775807n, [255, 255, 255, 255, 255, 255, 255, 127, 7, 8]);
|
||||
_assert(-9223372036854775808n, [0, 0, 0, 0, 0, 0, 0, 128, 7, 8]);
|
||||
_assert(18446744073709551615n, [255, 255, 255, 255, 255, 255, 255, 255, 11, 8]);
|
||||
_assert(4.5, [0, 0, 144, 64, 14, 4]);
|
||||
_assert(0.10000000149011612, [205, 204, 204, 61, 14, 4]);
|
||||
_assert(0.1, [154, 153, 153, 153, 153, 153, 185, 63, 15, 8]);
|
||||
_assert(-1025, [255, 251, 5, 2]);
|
||||
_assert("Maxim", [5, 77, 97, 120, 105, 109, 0, 6, 20, 1]);
|
||||
_assert("hello 😱", [10, 104, 101, 108, 108, 111, 32, 240, 159, 152, 177, 0, 11, 20, 1]);
|
||||
_assert({a:12}, [97, 0, 1, 3, 1, 1, 1, 12, 4, 2, 36, 1]);
|
||||
_assert({"":45, "a": 12}, [0, 97, 0, 2, 4, 4, 2, 1, 2, 45, 12, 4, 4, 4, 36, 1]);
|
||||
}
|
||||
|
||||
function testEncode() {
|
||||
function _assert(value, buffer) {
|
||||
assert.deepStrictEqual(flexbuffers.encode(value), new Uint8Array(buffer));
|
||||
}
|
||||
_assert(null, [0, 0, 1]);
|
||||
_assert(true, [1, 104, 1]);
|
||||
_assert(false, [0, 104, 1]);
|
||||
_assert(1, [1, 4, 1]);
|
||||
_assert(230, [230, 0, 5, 2]);
|
||||
_assert(1025, [1, 4, 5, 2]);
|
||||
_assert(-1025, [255, 251, 5, 2]);
|
||||
_assert(0x100000001, [1, 0, 0, 0, 1, 0, 0, 0, 7, 8]);
|
||||
_assert(0.1, [154, 153, 153, 153, 153, 153, 185, 63, 15, 8]);
|
||||
_assert(0.5, [0, 0, 0, 63, 14, 4]);
|
||||
_assert(new Uint8Array([1, 2, 3]), [3, 1, 2, 3, 3, 100, 1]);
|
||||
_assert("Maxim", [5, 77, 97, 120, 105, 109, 0, 6, 20, 1]);
|
||||
_assert("hello 😱", [10, 104, 101, 108, 108, 111, 32, 240, 159, 152, 177, 0, 11, 20, 1]);
|
||||
_assert([1, 2], [1, 2, 2, 64, 1]);
|
||||
_assert([-1, 256], [255, 255, 0, 1, 4, 65, 1]);
|
||||
_assert([-45, 256000], [211, 255, 255, 255, 0, 232, 3, 0, 8, 66, 1]);
|
||||
_assert([1.1, -256.0], [2, 0, 0, 0, 0, 0, 0, 0, 154, 153, 153, 153, 153, 153, 241, 63, 0, 255, 255, 255, 255, 255, 255, 255, 15, 5, 18, 43, 1]);
|
||||
_assert([1, 2, 4], [1, 2, 4, 3, 76, 1]);
|
||||
_assert([-1, 256, 4], [255, 255, 0, 1, 4, 0, 6, 77, 1]);
|
||||
_assert([[61], 64], [1, 61, 2, 2, 64, 44, 4, 4, 40, 1]);
|
||||
_assert(["foo", "bar", "baz"], [3, 102, 111, 111, 0, 3, 98, 97, 114, 0, 3, 98, 97, 122, 0, 3, 15, 11, 7, 3, 60, 1]);
|
||||
_assert(["foo", "bar", "baz", "foo", "bar", "baz"], [3, 102, 111, 111, 0, 3, 98, 97, 114, 0, 3, 98, 97, 122, 0, 6, 15, 11, 7, 18, 14, 10, 6, 60, 1]);
|
||||
_assert([true, false, true], [3, 1, 0, 1, 3, 144, 1]);
|
||||
_assert(['foo', 1, -5, 1.3, true], [
|
||||
3, 102, 111, 111, 0, 0, 0, 0,
|
||||
5, 0, 0, 0, 0, 0, 0, 0,
|
||||
15, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0, 0, 0, 0,
|
||||
251, 255, 255, 255, 255, 255, 255, 255,
|
||||
205, 204, 204, 204, 204, 204, 244, 63,
|
||||
1, 0, 0, 0, 0, 0, 0, 0,
|
||||
20, 4, 4, 15, 104, 45, 43, 1
|
||||
]);
|
||||
_assert([1, 3.3, 'max', true, null, false], [
|
||||
3, 109, 97, 120, 0, 0, 0, 0,
|
||||
6, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0, 0, 0, 0,
|
||||
102, 102, 102, 102, 102, 102, 10, 64,
|
||||
31, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
4, 15, 20, 104, 0, 104, 54, 43, 1
|
||||
]);
|
||||
_assert({"a": 12}, [97, 0, 1, 3, 1, 1, 1, 12, 4, 2, 36, 1]);
|
||||
_assert({"a": 12, "":45}, [0, 97, 0, 2, 4, 4, 2, 1, 2, 45, 12, 4, 4, 4, 36, 1]);
|
||||
// JS currently does not support key vector offset sharing
|
||||
_assert([{'something':12}, {'something': 45}], [
|
||||
115, 111, 109, 101, 116, 104, 105, 110, 103, 0,
|
||||
1, 11, 1, 1, 1, 12, 4, 6, 1, 1, 45, 4, 2, 8, 4, 36, 36, 4, 40, 1
|
||||
]);
|
||||
}
|
||||
|
||||
function testDeduplicationOff() {
|
||||
let buffer = flexbuffers.encode([{'something':12}, {'something': 45}], 1, true, true, false);
|
||||
assert.deepStrictEqual(buffer, new Uint8Array([
|
||||
115, 111, 109, 101, 116, 104, 105, 110, 103,
|
||||
0, 1, 11, 1, 1, 1, 12, 4, 1,
|
||||
18, 1, 1, 1, 45, 4, 2, 10, 4,
|
||||
36, 36, 4, 40, 1
|
||||
]));
|
||||
|
||||
buffer = flexbuffers.encode([{'something':12}, {'something': 45}], 1, true, false, false);
|
||||
assert.deepStrictEqual(buffer, new Uint8Array([
|
||||
115, 111, 109, 101, 116, 104, 105, 110, 103, 0,
|
||||
1, 11, 1, 1, 1, 12, 4, 115, 111, 109,
|
||||
101, 116, 104, 105, 110, 103, 0, 1, 11, 1,
|
||||
1, 1, 45, 4, 2, 20, 4, 36, 36, 4,
|
||||
40, 1
|
||||
]));
|
||||
|
||||
buffer = flexbuffers.encode(['something', 'something', 'dark'], 1, true, false, false);
|
||||
assert.deepStrictEqual(buffer, new Uint8Array([
|
||||
9, 115, 111, 109, 101, 116, 104,
|
||||
105, 110, 103, 0, 4, 100, 97,
|
||||
114, 107, 0, 3, 17, 18, 8,
|
||||
3, 60, 1
|
||||
]));
|
||||
|
||||
buffer = flexbuffers.encode(['something', 'something', 'dark'], 1, false, false, false);
|
||||
assert.deepStrictEqual(buffer, new Uint8Array([
|
||||
9, 115, 111, 109, 101, 116, 104, 105, 110,
|
||||
103, 0, 9, 115, 111, 109, 101, 116, 104,
|
||||
105, 110, 103, 0, 4, 100, 97, 114, 107,
|
||||
0, 3, 28, 18, 8, 3, 60, 1
|
||||
]));
|
||||
}
|
||||
|
||||
function testIndirectAdd() {
|
||||
function _assertInt(buffer, value, indirect = false, cache = false) {
|
||||
const builder = flexbuffers.builder();
|
||||
builder.addInt(value, indirect, cache);
|
||||
const data = builder.finish();
|
||||
assert.deepStrictEqual(data, new Uint8Array(buffer));
|
||||
}
|
||||
function _assertUInt(buffer, value, indirect = false, cache = false) {
|
||||
const builder = flexbuffers.builder();
|
||||
builder.addUInt(value, indirect, cache);
|
||||
const data = builder.finish();
|
||||
assert.deepStrictEqual(data, new Uint8Array(buffer));
|
||||
}
|
||||
function _assertFloat(buffer, value, indirect = false, cache = false) {
|
||||
const builder = flexbuffers.builder();
|
||||
builder.addFloat(value, indirect, cache);
|
||||
const data = builder.finish();
|
||||
assert.deepStrictEqual(data, new Uint8Array(buffer));
|
||||
}
|
||||
_assertInt([0, 4, 1], 0);
|
||||
_assertInt([0, 1, 24, 1], 0, true);
|
||||
_assertInt([255, 0, 5, 2], 255);
|
||||
|
||||
_assertUInt([0, 8, 1], 0);
|
||||
_assertUInt([0, 1, 28, 1], 0, true);
|
||||
_assertUInt([255, 8, 1], 255);
|
||||
|
||||
_assertUInt([185, 115, 175, 118, 250, 84, 8, 0, 11, 8], 2345234523452345);
|
||||
_assertUInt([185, 115, 175, 118, 250, 84, 8, 0, 8, 31, 1], 2345234523452345, true);
|
||||
_assertInt([185, 115, 175, 118, 250, 84, 8, 0, 7, 8], 2345234523452345);
|
||||
_assertInt([185, 115, 175, 118, 250, 84, 8, 0, 8, 27, 1], 2345234523452345, true);
|
||||
|
||||
_assertFloat([154, 153, 153, 153, 153, 153, 185, 63, 15, 8], 0.1);
|
||||
_assertFloat([154, 153, 153, 153, 153, 153, 185, 63, 8, 35, 1], 0.1, true);
|
||||
_assertFloat([0, 0, 0, 0, 14, 4], 0);
|
||||
_assertFloat([0, 0, 0, 0, 4, 34, 1], 0, true);
|
||||
}
|
||||
|
||||
function testIndirectWithCache() {
|
||||
function _assertInt(buffer, values) {
|
||||
const builder = flexbuffers.builder();
|
||||
builder.startVector();
|
||||
values.forEach(v => {
|
||||
builder.addInt(v, true, true)
|
||||
});
|
||||
builder.end();
|
||||
const data = builder.finish();
|
||||
assert.deepStrictEqual(data, new Uint8Array(buffer));
|
||||
}
|
||||
|
||||
function _assertUInt(buffer, values) {
|
||||
const builder = flexbuffers.builder();
|
||||
builder.startVector();
|
||||
values.forEach(v => {
|
||||
builder.addUInt(v, true, true);
|
||||
});
|
||||
builder.end();
|
||||
const data = builder.finish();
|
||||
assert.deepStrictEqual(data, new Uint8Array(buffer));
|
||||
}
|
||||
|
||||
function _assertFloat(buffer, values) {
|
||||
const builder = flexbuffers.builder();
|
||||
builder.startVector();
|
||||
values.forEach(v => {
|
||||
builder.addFloat(v, true, true);
|
||||
});
|
||||
builder.end();
|
||||
const data = builder.finish();
|
||||
assert.deepStrictEqual(data, new Uint8Array(buffer));
|
||||
}
|
||||
|
||||
_assertInt(
|
||||
[185, 115, 175, 118, 250, 84, 8, 0, 4, 9, 10, 11, 12, 27, 27, 27, 27, 8, 40, 1],
|
||||
[2345234523452345, 2345234523452345, 2345234523452345, 2345234523452345]
|
||||
);
|
||||
|
||||
_assertUInt(
|
||||
[185, 115, 175, 118, 250, 84, 8, 0, 4, 9, 10, 11, 12, 31, 31, 31, 31, 8, 40, 1],
|
||||
[2345234523452345, 2345234523452345, 2345234523452345, 2345234523452345]
|
||||
);
|
||||
|
||||
_assertFloat(
|
||||
[154, 153, 153, 153, 153, 153, 185, 63, 4, 9, 10, 11, 12, 35, 35, 35, 35, 8, 40, 1],
|
||||
[0.1, 0.1, 0.1, 0.1]
|
||||
);
|
||||
}
|
||||
|
||||
function testMapBuilder() {
|
||||
const builder = flexbuffers.builder();
|
||||
builder.startMap();
|
||||
builder.addKey('a');
|
||||
builder.add(12);
|
||||
builder.addKey('');
|
||||
builder.add(45);
|
||||
builder.end();
|
||||
const data = builder.finish();
|
||||
assert.deepStrictEqual(data, new Uint8Array([97, 0, 0, 2, 2, 5, 2, 1, 2, 45, 12, 4, 4, 4, 36, 1]));
|
||||
}
|
||||
|
||||
function testRoundTrip() {
|
||||
const example = {
|
||||
"age": 35,
|
||||
"flags": [true, false, true, true],
|
||||
"weight": 72.5,
|
||||
"name": "Maxim",
|
||||
"address": {
|
||||
"city": "Bla",
|
||||
"zip": "12345",
|
||||
"countryCode": "XX",
|
||||
}
|
||||
};
|
||||
|
||||
function _assert(value) {
|
||||
let buffer = flexbuffers.encode(value, 1);
|
||||
let o = flexbuffers.toObject(buffer.buffer);
|
||||
assert.deepStrictEqual(o, value);
|
||||
}
|
||||
|
||||
_assert(example);
|
||||
_assert(0x100000001n);
|
||||
_assert({ test_number: 72.6 })
|
||||
}
|
||||
|
||||
function testRoundTripWithBuilder() {
|
||||
const example = {
|
||||
"age": 35,
|
||||
"flags": [true, false, true, true],
|
||||
"weight": 72.5,
|
||||
"name": "Maxim",
|
||||
"address": {
|
||||
"city": "Bla",
|
||||
"zip": "12345",
|
||||
"countryCode": "XX",
|
||||
}
|
||||
};
|
||||
|
||||
const builder = flexbuffers.builder();
|
||||
builder.startMap();
|
||||
|
||||
builder.addKey('age');
|
||||
builder.add(35);
|
||||
|
||||
builder.addKey('flags');
|
||||
builder.startVector();
|
||||
builder.add(true);
|
||||
builder.add(false);
|
||||
builder.add(true);
|
||||
builder.add(true);
|
||||
builder.end();
|
||||
|
||||
builder.addKey("weight");
|
||||
builder.add(72.5);
|
||||
|
||||
builder.addKey("name");
|
||||
builder.add("Maxim");
|
||||
|
||||
builder.addKey("address");
|
||||
|
||||
builder.startMap();
|
||||
builder.addKey("city");
|
||||
builder.add("Bla");
|
||||
builder.addKey("zip");
|
||||
builder.add("12345");
|
||||
builder.addKey("countryCode");
|
||||
builder.add("XX");
|
||||
builder.end();
|
||||
|
||||
builder.end();
|
||||
|
||||
const data = builder.finish();
|
||||
let o = flexbuffers.toObject(data.buffer);
|
||||
assert.deepStrictEqual(o, example);
|
||||
|
||||
let root = flexbuffers.toReference(data.buffer);
|
||||
assert.strictEqual(root.isMap(), true);
|
||||
assert.strictEqual(root.get("age").numericValue(), 35);
|
||||
assert.strictEqual(root.get("age").intValue(), 35);
|
||||
assert.strictEqual(root.get("name").stringValue(), "Maxim");
|
||||
assert.strictEqual(root.get("weight").floatValue(), 72.5);
|
||||
assert.strictEqual(root.get("weight").numericValue(), 72.5);
|
||||
let flags = root.get("flags");
|
||||
assert.strictEqual(flags.isVector(), true);
|
||||
assert.strictEqual(flags.length(), 4);
|
||||
assert.strictEqual(flags.get(0).boolValue(), true);
|
||||
assert.strictEqual(flags.get(1).boolValue(), false);
|
||||
assert.strictEqual(flags.get(2).boolValue(), true);
|
||||
assert.strictEqual(flags.get(3).boolValue(), true);
|
||||
|
||||
let address = root.get("address");
|
||||
assert.strictEqual(address.isMap(), true);
|
||||
assert.strictEqual(address.length(), 3);
|
||||
assert.strictEqual(address.get("city").stringValue(), "Bla");
|
||||
assert.strictEqual(address.get("zip").stringValue(), "12345");
|
||||
assert.strictEqual(address.get("countryCode").stringValue(), "XX");
|
||||
}
|
||||
|
||||
function testGoldBuffer() {
|
||||
const data = new Uint8Array(fs.readFileSync('../gold_flexbuffer_example.bin')).buffer;
|
||||
const b1 = flexbuffers.toReference(data).get("bools").get(1);
|
||||
assert.strictEqual(b1.isBool(), true);
|
||||
assert.strictEqual(b1.boolValue(), false);
|
||||
|
||||
const blob = flexbuffers.toReference(data).get("vec").get(3);
|
||||
assert.strictEqual(blob.isBlob(), true);
|
||||
assert.deepStrictEqual(blob.blobValue(), new Uint8Array([77]));
|
||||
|
||||
const o = flexbuffers.toObject(data);
|
||||
assert.deepStrictEqual(o, {
|
||||
bool: true,
|
||||
bools: [true, false, true, false],
|
||||
bar: [1, 2, 3],
|
||||
bar3: [1, 2, 3],
|
||||
foo: 100,
|
||||
mymap: {foo:'Fred'},
|
||||
vec: [-100, 'Fred', 4, new Uint8Array([77]), false, 4]
|
||||
});
|
||||
}
|
||||
|
||||
function testBugWhereOffestWereStoredAsIntInsteadOfUInt() {
|
||||
// Reported in https://github.com/google/flatbuffers/issues/5949#issuecomment-688421193
|
||||
const object = {'channels_in': 64, 'dilation_height_factor': 1, 'dilation_width_factor': 1, 'fused_activation_function': 1, 'pad_values': 1, 'padding': 0, 'stride_height': 1, 'stride_width': 1};
|
||||
let data1 = flexbuffers.encode(object);
|
||||
const data = [99, 104, 97, 110, 110, 101, 108, 115, 95, 105, 110, 0,
|
||||
100, 105, 108, 97, 116, 105, 111, 110, 95, 104, 101, 105, 103, 104, 116, 95, 102, 97, 99, 116, 111, 114, 0,
|
||||
100, 105, 108, 97, 116, 105, 111, 110, 95, 119, 105, 100, 116, 104, 95, 102, 97, 99, 116, 111, 114, 0,
|
||||
102, 117, 115, 101, 100, 95, 97, 99, 116, 105, 118, 97, 116, 105, 111, 110, 95, 102, 117, 110, 99, 116, 105, 111, 110, 0,
|
||||
112, 97, 100, 95, 118, 97, 108, 117, 101, 115, 0, 112, 97, 100, 100, 105, 110, 103, 0,
|
||||
115, 116, 114, 105, 100, 101, 95, 104, 101, 105, 103, 104, 116, 0,
|
||||
115, 116, 114, 105, 100, 101, 95, 119, 105, 100, 116, 104, 0,
|
||||
8, 130, 119, 97, 76, 51, 41, 34, 21, 8, 1, 8, 64, 1, 1, 1, 1, 0, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 16, 36, 1];
|
||||
let object2 = flexbuffers.toObject(new Uint8Array(data).buffer);
|
||||
let object1 = flexbuffers.toObject(new Uint8Array(data1).buffer);
|
||||
assert.deepStrictEqual(object, object2);
|
||||
assert.deepStrictEqual(object, object1);
|
||||
assert.strictEqual(data.length, data1.length);
|
||||
let ref = flexbuffers.toReference(new Uint8Array(data).buffer);
|
||||
assert.strictEqual(ref.isMap(), true);
|
||||
assert.strictEqual(ref.length(), 8);
|
||||
assert.strictEqual(ref.get("channels_in").numericValue(), 64);
|
||||
assert.strictEqual(ref.get("padding").isNumber(), true);
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
480
tests/ts/JavaScriptTest.js
Normal file
480
tests/ts/JavaScriptTest.js
Normal file
@@ -0,0 +1,480 @@
|
||||
// Run this using JavaScriptTest.sh
|
||||
import assert from 'assert'
|
||||
import fs from 'fs'
|
||||
import * as flatbuffers from 'flatbuffers'
|
||||
|
||||
import { Monster, MonsterT } from './my-game/example/monster.js'
|
||||
import { Test, TestT } from './my-game/example/test.js'
|
||||
import { Stat } from './my-game/example/stat.js'
|
||||
import { Vec3 } from './my-game/example/vec3.js'
|
||||
import { Color } from './my-game/example/color.js';
|
||||
import { Any } from './my-game/example/any.js';
|
||||
|
||||
function main() {
|
||||
|
||||
// First, let's test reading a FlatBuffer generated by C++ code:
|
||||
// This file was generated from monsterdata_test.json
|
||||
var data = new Uint8Array(fs.readFileSync('../monsterdata_test.mon'));
|
||||
|
||||
// Now test it:
|
||||
|
||||
var bb = new flatbuffers.ByteBuffer(data);
|
||||
testBuffer(bb);
|
||||
|
||||
// Second, let's create a FlatBuffer from scratch in JavaScript, and test it also.
|
||||
// We use an initial size of 1 to exercise the reallocation algorithm,
|
||||
// normally a size larger than the typical FlatBuffer you generate would be
|
||||
// better for performance.
|
||||
var fbb = new flatbuffers.Builder(1);
|
||||
createMonster(fbb);
|
||||
serializeAndTest(fbb);
|
||||
testObjApiPack(fbb);
|
||||
|
||||
// clear the builder, repeat tests
|
||||
var clearIterations = 100;
|
||||
var startingCapacity = fbb.bb.capacity();
|
||||
for (var i = 0; i < clearIterations; i++) {
|
||||
fbb.clear();
|
||||
createMonster(fbb);
|
||||
serializeAndTest(fbb);
|
||||
testObjApiPack(fbb);
|
||||
}
|
||||
// the capacity of our buffer shouldn't increase with the same size payload
|
||||
assert.strictEqual(fbb.bb.capacity(), startingCapacity);
|
||||
|
||||
test64bit();
|
||||
testUnicode();
|
||||
fuzzTest1();
|
||||
testNullStrings();
|
||||
testSharedStrings();
|
||||
testVectorOfStructs();
|
||||
|
||||
console.log('FlatBuffers test: completed successfully');
|
||||
}
|
||||
|
||||
function createMonster(fbb) {
|
||||
// We set up the same values as monsterdata.json:
|
||||
|
||||
var str = fbb.createString('MyMonster');
|
||||
|
||||
var inv = Monster.createInventoryVector(fbb, [0, 1, 2, 3, 4]);
|
||||
|
||||
var fred = fbb.createString('Fred');
|
||||
Monster.startMonster(fbb);
|
||||
Monster.addName(fbb, fred);
|
||||
var mon2 = Monster.endMonster(fbb);
|
||||
|
||||
Monster.startTest4Vector(fbb, 2);
|
||||
Test.createTest(fbb, 10, 20);
|
||||
Test.createTest(fbb, 30, 40);
|
||||
var test4 = fbb.endVector();
|
||||
|
||||
var testArrayOfString = Monster.createTestarrayofstringVector(fbb, [
|
||||
fbb.createString('test1'),
|
||||
fbb.createString('test2')
|
||||
]);
|
||||
|
||||
var testVectorOfLongs = Monster.createVectorOfLongsVector(fbb, [
|
||||
1n,
|
||||
101010100n
|
||||
]);
|
||||
|
||||
Monster.startMonster(fbb);
|
||||
Monster.addPos(fbb, Vec3.createVec3(fbb, 1, 2, 3, 3, Color.Green, 5, 6));
|
||||
Monster.addHp(fbb, 80);
|
||||
Monster.addName(fbb, str);
|
||||
Monster.addInventory(fbb, inv);
|
||||
Monster.addTestType(fbb, Any.Monster);
|
||||
Monster.addTest(fbb, mon2);
|
||||
Monster.addTest4(fbb, test4);
|
||||
Monster.addTestarrayofstring(fbb, testArrayOfString);
|
||||
Monster.addVectorOfLongs(fbb, testVectorOfLongs);
|
||||
Monster.addTestbool(fbb, true);
|
||||
var mon = Monster.endMonster(fbb);
|
||||
|
||||
Monster.finishMonsterBuffer(fbb, mon);
|
||||
}
|
||||
|
||||
function serializeAndTest(fbb) {
|
||||
// Write the result to a file for debugging purposes:
|
||||
// Note that the binaries are not necessarily identical, since the JSON
|
||||
// parser may serialize in a slightly different order than the above
|
||||
// JavaScript code. They are functionally equivalent though.
|
||||
|
||||
fs.writeFileSync('monsterdata_javascript_wire.mon', Buffer.from(fbb.asUint8Array()));
|
||||
|
||||
// Tests mutation first. This will verify that we did not trample any other
|
||||
// part of the byte buffer.
|
||||
testMutation(fbb.dataBuffer());
|
||||
|
||||
testBuffer(fbb.dataBuffer());
|
||||
}
|
||||
|
||||
function testMutation(bb) {
|
||||
var monster = Monster.getRootAsMonster(bb);
|
||||
|
||||
monster.mutate_hp(120);
|
||||
assert.strictEqual(monster.hp(), 120);
|
||||
|
||||
monster.mutate_hp(80);
|
||||
assert.strictEqual(monster.hp(), 80);
|
||||
|
||||
var manaRes = monster.mutate_mana(10);
|
||||
assert.strictEqual(manaRes, false); // Field was NOT present, because default value.
|
||||
|
||||
// TODO: There is not the availability to mutate structs or vectors.
|
||||
}
|
||||
|
||||
function testObjApiPack(fbb) {
|
||||
fbb.clear();
|
||||
createMonster(fbb);
|
||||
let monster_t = Monster.getRootAsMonster(fbb.dataBuffer()).unpack();
|
||||
fbb.clear();
|
||||
Monster.finishMonsterBuffer(fbb, monster_t.pack(fbb));
|
||||
serializeAndTest(fbb);
|
||||
}
|
||||
|
||||
function testObjApiUnpack(monster) {
|
||||
assert.strictEqual(monster.hp, 80);
|
||||
assert.strictEqual(monster.mana, 150); // default
|
||||
|
||||
assert.strictEqual(monster.name, 'MyMonster');
|
||||
|
||||
let pos = monster.pos;
|
||||
assert.strictEqual(pos.x, 1);
|
||||
assert.strictEqual(pos.y, 2);
|
||||
assert.strictEqual(pos.z, 3);
|
||||
assert.strictEqual(pos.test1, 3);
|
||||
assert.strictEqual(pos.test2, Color.Green);
|
||||
let test3 = pos.test3;
|
||||
assert.strictEqual(test3.a, 5);
|
||||
assert.strictEqual(test3.b, 6);
|
||||
|
||||
assert.strictEqual(monster.testType, Any.Monster);
|
||||
let monster2 = monster.test;
|
||||
assert.strictEqual(monster2 != null, true);
|
||||
assert.strictEqual(monster2 instanceof MonsterT, true);
|
||||
assert.strictEqual(monster2.name, 'Fred');
|
||||
|
||||
assert.strictEqual(monster.inventory.length, 5);
|
||||
let invsum = 0;
|
||||
for (let i = 0; i < monster.inventory.length; i++) {
|
||||
invsum += monster.inventory[i];
|
||||
}
|
||||
assert.strictEqual(invsum, 10);
|
||||
|
||||
let test_0 = monster.test4[0];
|
||||
let test_1 = monster.test4[1];
|
||||
assert.strictEqual(monster.test4.length, 2);
|
||||
assert.strictEqual(test_0.a + test_0.b + test_1.a + test_1.b, 100);
|
||||
|
||||
assert.strictEqual(monster.testarrayofstring.length, 2);
|
||||
assert.strictEqual(monster.testarrayofstring[0], 'test1');
|
||||
assert.strictEqual(monster.testarrayofstring[1], 'test2');
|
||||
|
||||
assert.strictEqual(monster.testbool, true);
|
||||
}
|
||||
|
||||
function testBuffer(bb) {
|
||||
assert.ok(Monster.bufferHasIdentifier(bb));
|
||||
|
||||
var monster = Monster.getRootAsMonster(bb);
|
||||
|
||||
assert.strictEqual(monster.hp(), 80);
|
||||
assert.strictEqual(monster.mana(), 150); // default
|
||||
|
||||
assert.strictEqual(monster.name(), 'MyMonster');
|
||||
|
||||
var pos = monster.pos();
|
||||
assert.strictEqual(pos.x(), 1);
|
||||
assert.strictEqual(pos.y(), 2);
|
||||
assert.strictEqual(pos.z(), 3);
|
||||
assert.strictEqual(pos.test1(), 3);
|
||||
assert.strictEqual(pos.test2(), Color.Green);
|
||||
var t = pos.test3();
|
||||
assert.strictEqual(t.a(), 5);
|
||||
assert.strictEqual(t.b(), 6);
|
||||
|
||||
assert.strictEqual(monster.testType(), Any.Monster);
|
||||
var monster2 = new Monster();
|
||||
assert.strictEqual(monster.test(monster2) != null, true);
|
||||
assert.strictEqual(monster2.name(), 'Fred');
|
||||
|
||||
assert.strictEqual(monster.inventoryLength(), 5);
|
||||
var invsum = 0;
|
||||
for (var i = 0; i < monster.inventoryLength(); i++) {
|
||||
invsum += monster.inventory(i);
|
||||
}
|
||||
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);
|
||||
|
||||
let longSum = 0n;
|
||||
for (let idx = 0; idx < monster.vectorOfLongsLength(); ++idx) {
|
||||
longSum += monster.vectorOfLongs(idx);
|
||||
}
|
||||
assert.strictEqual(longSum, 101010101n);
|
||||
|
||||
var test_0 = monster.test4(0);
|
||||
var test_1 = monster.test4(1);
|
||||
assert.strictEqual(monster.test4Length(), 2);
|
||||
assert.strictEqual(test_0.a() + test_0.b() + test_1.a() + test_1.b(), 100);
|
||||
|
||||
assert.strictEqual(monster.testarrayofstringLength(), 2);
|
||||
assert.strictEqual(monster.testarrayofstring(0), 'test1');
|
||||
assert.strictEqual(monster.testarrayofstring(1), 'test2');
|
||||
|
||||
assert.strictEqual(monster.testbool(), true);
|
||||
|
||||
let monster_t = monster.unpack();
|
||||
testObjApiUnpack(monster_t);
|
||||
|
||||
let monster2_t = new MonsterT();
|
||||
monster.unpackTo(monster2_t);
|
||||
testObjApiUnpack(monster2_t);
|
||||
}
|
||||
|
||||
function test64bit() {
|
||||
var fbb = new flatbuffers.Builder();
|
||||
var required = fbb.createString('required');
|
||||
|
||||
Stat.startStat(fbb);
|
||||
var stat2 = Stat.endStat(fbb);
|
||||
|
||||
Monster.startMonster(fbb);
|
||||
Monster.addName(fbb, required);
|
||||
Monster.addTestempty(fbb, stat2);
|
||||
var mon2 = Monster.endMonster(fbb);
|
||||
|
||||
Stat.startStat(fbb);
|
||||
// 2541551405100253985 = 0x2345678987654321
|
||||
Stat.addVal(fbb, 0x2345678987654321n);
|
||||
var stat = Stat.endStat(fbb);
|
||||
|
||||
Monster.startMonster(fbb);
|
||||
Monster.addName(fbb, required);
|
||||
Monster.addEnemy(fbb, mon2);
|
||||
Monster.addTestempty(fbb, stat);
|
||||
var mon = Monster.endMonster(fbb);
|
||||
|
||||
Monster.finishMonsterBuffer(fbb, mon);
|
||||
var bytes = fbb.asUint8Array();
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
var bb = new flatbuffers.ByteBuffer(bytes);
|
||||
assert.ok(Monster.bufferHasIdentifier(bb));
|
||||
var mon = Monster.getRootAsMonster(bb);
|
||||
|
||||
var stat = mon.testempty();
|
||||
assert.strictEqual(stat != null, true);
|
||||
assert.strictEqual(stat.val() != null, true);
|
||||
assert.strictEqual(stat.val(), 2541551405100253985n);
|
||||
|
||||
var mon2 = mon.enemy();
|
||||
assert.strictEqual(mon2 != null, true);
|
||||
stat = mon2.testempty();
|
||||
assert.strictEqual(stat != null, true);
|
||||
assert.strictEqual(stat.val() != null, true);
|
||||
assert.strictEqual(stat.val(), 0n); // default value
|
||||
}
|
||||
|
||||
function testUnicode() {
|
||||
var correct = fs.readFileSync('../unicode_test.mon');
|
||||
var json = JSON.parse(fs.readFileSync('../unicode_test.json', 'utf8'));
|
||||
|
||||
// Test reading
|
||||
function testReadingUnicode(bb) {
|
||||
var monster = Monster.getRootAsMonster(bb);
|
||||
assert.strictEqual(monster.name(), json.name);
|
||||
assert.deepEqual(Buffer.from(monster.name(flatbuffers.Encoding.UTF8_BYTES)), Buffer.from(json.name));
|
||||
assert.strictEqual(monster.testarrayoftablesLength(), json.testarrayoftables.length);
|
||||
json.testarrayoftables.forEach(function(table, i) {
|
||||
var value = monster.testarrayoftables(i);
|
||||
assert.strictEqual(value.name(), table.name);
|
||||
assert.deepEqual(Buffer.from(value.name(flatbuffers.Encoding.UTF8_BYTES)), Buffer.from(table.name));
|
||||
});
|
||||
assert.strictEqual(monster.testarrayofstringLength(), json.testarrayofstring.length);
|
||||
json.testarrayofstring.forEach(function(string, i) {
|
||||
assert.strictEqual(monster.testarrayofstring(i), string);
|
||||
assert.deepEqual(Buffer.from(monster.testarrayofstring(i, flatbuffers.Encoding.UTF8_BYTES)), Buffer.from(string));
|
||||
});
|
||||
}
|
||||
testReadingUnicode(new flatbuffers.ByteBuffer(new Uint8Array(correct)));
|
||||
|
||||
// Test writing
|
||||
var fbb = new flatbuffers.Builder();
|
||||
var name = fbb.createString(json.name);
|
||||
var testarrayoftablesOffsets = json.testarrayoftables.map(function(table) {
|
||||
var name = fbb.createString(new Uint8Array(Buffer.from(table.name)));
|
||||
Monster.startMonster(fbb);
|
||||
Monster.addName(fbb, name);
|
||||
return Monster.endMonster(fbb);
|
||||
});
|
||||
var testarrayoftablesOffset = Monster.createTestarrayoftablesVector(fbb,
|
||||
testarrayoftablesOffsets);
|
||||
var testarrayofstringOffset = Monster.createTestarrayofstringVector(fbb,
|
||||
json.testarrayofstring.map(function(string) { return fbb.createString(string); }));
|
||||
Monster.startMonster(fbb);
|
||||
Monster.addTestarrayofstring(fbb, testarrayofstringOffset);
|
||||
Monster.addTestarrayoftables(fbb, testarrayoftablesOffset);
|
||||
Monster.addName(fbb, name);
|
||||
Monster.finishSizePrefixedMonsterBuffer(fbb, Monster.endMonster(fbb));
|
||||
var bb = new flatbuffers.ByteBuffer(fbb.asUint8Array())
|
||||
bb.setPosition(4);
|
||||
testReadingUnicode(bb);
|
||||
}
|
||||
|
||||
var __imul = Math.imul ? Math.imul : function(a, b) {
|
||||
var ah = a >> 16 & 65535;
|
||||
var bh = b >> 16 & 65535;
|
||||
var al = a & 65535;
|
||||
var bl = b & 65535;
|
||||
return al * bl + (ah * bl + al * bh << 16) | 0;
|
||||
};
|
||||
|
||||
// Include simple random number generator to ensure results will be the
|
||||
// same cross platform.
|
||||
// http://en.wikipedia.org/wiki/Park%E2%80%93Miller_random_number_generator
|
||||
var lcg_seed = 48271;
|
||||
|
||||
function lcg_rand() {
|
||||
return lcg_seed = (__imul(lcg_seed, 279470273) >>> 0) % 4294967291;
|
||||
}
|
||||
|
||||
function lcg_reset() {
|
||||
lcg_seed = 48271;
|
||||
}
|
||||
|
||||
// Converts a Field ID to a virtual table offset.
|
||||
function fieldIndexToOffset(field_id) {
|
||||
// Should correspond to what EndTable() below builds up.
|
||||
var fixed_fields = 2; // Vtable size and Object Size.
|
||||
return (field_id + fixed_fields) * 2;
|
||||
}
|
||||
|
||||
// Low level stress/fuzz test: serialize/deserialize a variety of
|
||||
// different kinds of data in different combinations
|
||||
function fuzzTest1() {
|
||||
|
||||
// Values we're testing against: chosen to ensure no bits get chopped
|
||||
// off anywhere, and also be different from eachother.
|
||||
var bool_val = true;
|
||||
var char_val = -127; // 0x81
|
||||
var uchar_val = 0xFF;
|
||||
var short_val = -32222; // 0x8222;
|
||||
var ushort_val = 0xFEEE;
|
||||
var int_val = 0x83333333 | 0;
|
||||
var uint_val = 0xFDDDDDDD;
|
||||
var long_val = BigInt.asIntN(64, 0x8444444444444444n);
|
||||
var ulong_val = BigInt.asUintN(64, 0xFCCCCCCCCCCCCCCCn);
|
||||
var float_val = new Float32Array([3.14159])[0];
|
||||
var double_val = 3.14159265359;
|
||||
|
||||
var test_values_max = 11;
|
||||
var fields_per_object = 4;
|
||||
var num_fuzz_objects = 10000; // The higher, the more thorough :)
|
||||
|
||||
var builder = new flatbuffers.Builder();
|
||||
|
||||
lcg_reset(); // Keep it deterministic.
|
||||
|
||||
var objects = [];
|
||||
|
||||
// Generate num_fuzz_objects random objects each consisting of
|
||||
// fields_per_object fields, each of a random type.
|
||||
for (var i = 0; i < num_fuzz_objects; i++) {
|
||||
builder.startObject(fields_per_object);
|
||||
for (var f = 0; f < fields_per_object; f++) {
|
||||
var choice = lcg_rand() % test_values_max;
|
||||
switch (choice) {
|
||||
case 0: builder.addFieldInt8(f, bool_val, 0); break;
|
||||
case 1: builder.addFieldInt8(f, char_val, 0); break;
|
||||
case 2: builder.addFieldInt8(f, uchar_val, 0); break;
|
||||
case 3: builder.addFieldInt16(f, short_val, 0); break;
|
||||
case 4: builder.addFieldInt16(f, ushort_val, 0); break;
|
||||
case 5: builder.addFieldInt32(f, int_val, 0); break;
|
||||
case 6: builder.addFieldInt32(f, uint_val, 0); break;
|
||||
case 7: builder.addFieldInt64(f, long_val, 0n); break;
|
||||
case 8: builder.addFieldInt64(f, ulong_val, 0n); break;
|
||||
case 9: builder.addFieldFloat32(f, float_val, 0); break;
|
||||
case 10: builder.addFieldFloat64(f, double_val, 0); break;
|
||||
}
|
||||
}
|
||||
objects.push(builder.endObject());
|
||||
}
|
||||
builder.prep(8, 0); // Align whole buffer.
|
||||
|
||||
lcg_reset(); // Reset.
|
||||
|
||||
builder.finish(objects[objects.length - 1]);
|
||||
var bytes = new Uint8Array(builder.asUint8Array());
|
||||
var view = new DataView(bytes.buffer);
|
||||
|
||||
// Test that all objects we generated are readable and return the
|
||||
// expected values. We generate random objects in the same order
|
||||
// so this is deterministic.
|
||||
for (var i = 0; i < num_fuzz_objects; i++) {
|
||||
var offset = bytes.length - objects[i];
|
||||
for (var f = 0; f < fields_per_object; f++) {
|
||||
var choice = lcg_rand() % test_values_max;
|
||||
var vtable_offset = fieldIndexToOffset(f);
|
||||
var vtable = offset - view.getInt32(offset, true);
|
||||
assert.ok(vtable_offset < view.getInt16(vtable, true));
|
||||
var field_offset = offset + view.getInt16(vtable + vtable_offset, true);
|
||||
switch (choice) {
|
||||
case 0: assert.strictEqual(!!view.getInt8(field_offset), bool_val); break;
|
||||
case 1: assert.strictEqual(view.getInt8(field_offset), char_val); break;
|
||||
case 2: assert.strictEqual(view.getUint8(field_offset), uchar_val); break;
|
||||
case 3: assert.strictEqual(view.getInt16(field_offset, true), short_val); break;
|
||||
case 4: assert.strictEqual(view.getUint16(field_offset, true), ushort_val); break;
|
||||
case 5: assert.strictEqual(view.getInt32(field_offset, true), int_val); break;
|
||||
case 6: assert.strictEqual(view.getUint32(field_offset, true), uint_val); break;
|
||||
case 7: assert.strictEqual(view.getBigInt64(field_offset, true), long_val); break;
|
||||
case 8: assert.strictEqual(view.getBigUint64(field_offset, true), ulong_val); break;
|
||||
case 9: assert.strictEqual(view.getFloat32(field_offset, true), float_val); break;
|
||||
case 10: assert.strictEqual(view.getFloat64(field_offset, true), double_val); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function testSharedStrings() {
|
||||
var shared_string = "Hello world";
|
||||
var builder = new flatbuffers.Builder();
|
||||
let mainOffset = builder.createSharedString(shared_string);
|
||||
assert.strictEqual(builder.createSharedString(shared_string), mainOffset);
|
||||
}
|
||||
|
||||
function testNullStrings() {
|
||||
var builder = new flatbuffers.Builder();
|
||||
assert.strictEqual(builder.createString(null), 0);
|
||||
assert.strictEqual(builder.createSharedString(null), 0);
|
||||
assert.strictEqual(builder.createString(undefined), 0);
|
||||
assert.strictEqual(builder.createSharedString(undefined), 0);
|
||||
}
|
||||
|
||||
function testVectorOfStructs() {
|
||||
let monster = new MonsterT();
|
||||
monster.name = 'testVectorOfStructs';
|
||||
monster.test4 = [
|
||||
new TestT(1, 2),
|
||||
new TestT(3, 4)
|
||||
];
|
||||
|
||||
let builder = new flatbuffers.Builder();
|
||||
builder.finish(monster.pack(builder));
|
||||
|
||||
let decodedMonster = Monster.getRootAsMonster(builder.dataBuffer()).unpack();
|
||||
assert.strictEqual(decodedMonster.test4[0].a, 1);
|
||||
assert.strictEqual(decodedMonster.test4[0].b, 2);
|
||||
assert.strictEqual(decodedMonster.test4[1].a, 3);
|
||||
assert.strictEqual(decodedMonster.test4[1].b, 4);
|
||||
}
|
||||
|
||||
main();
|
||||
111
tests/ts/JavaScriptUnionVectorTest.js
Normal file
111
tests/ts/JavaScriptUnionVectorTest.js
Normal file
@@ -0,0 +1,111 @@
|
||||
import assert from 'assert'
|
||||
import * as flatbuffers from 'flatbuffers'
|
||||
|
||||
import { Character } from './union_vector/character.js'
|
||||
import { BookReader, BookReaderT } from './union_vector/book-reader.js'
|
||||
import { Attacker, AttackerT } from './union_vector/attacker.js'
|
||||
import { Movie, MovieT } from './union_vector/movie.js'
|
||||
|
||||
var charTypes = [
|
||||
Character.Belle,
|
||||
Character.MuLan,
|
||||
Character.BookFan,
|
||||
Character.Other
|
||||
];
|
||||
|
||||
function testMovieBuf(movie) {
|
||||
assert.strictEqual(movie.charactersTypeLength(), charTypes.length);
|
||||
assert.strictEqual(movie.charactersLength(), movie.charactersTypeLength());
|
||||
|
||||
for (var i = 0; i < charTypes.length; ++i) {
|
||||
assert.strictEqual(movie.charactersType(i), charTypes[i]);
|
||||
}
|
||||
|
||||
var bookReader7 = movie.characters(0, new BookReader());
|
||||
assert.strictEqual(bookReader7.booksRead(), 7);
|
||||
|
||||
var attacker = movie.characters(1, new Attacker());
|
||||
assert.strictEqual(attacker.swordAttackDamage(), 5);
|
||||
|
||||
var bookReader2 = movie.characters(2, new BookReader());
|
||||
assert.strictEqual(bookReader2.booksRead(), 2);
|
||||
|
||||
var other = movie.characters(3, '');
|
||||
assert.strictEqual(other, "I am other");
|
||||
}
|
||||
|
||||
function testMovieUnpack(movie) {
|
||||
assert.strictEqual(movie.charactersType.length, charTypes.length);
|
||||
assert.strictEqual(movie.characters.length, movie.charactersType.length);
|
||||
|
||||
for (var i = 0; i < charTypes.length; ++i) {
|
||||
assert.strictEqual(movie.charactersType[i], charTypes[i]);
|
||||
}
|
||||
|
||||
var bookReader7 = movie.characters[0];
|
||||
assert.strictEqual(bookReader7 instanceof BookReaderT, true);
|
||||
assert.strictEqual(bookReader7.booksRead, 7);
|
||||
|
||||
var attacker = movie.characters[1];
|
||||
assert.strictEqual(attacker instanceof AttackerT, true);
|
||||
assert.strictEqual(attacker.swordAttackDamage, 5);
|
||||
|
||||
var bookReader2 = movie.characters[2];
|
||||
assert.strictEqual(bookReader2 instanceof BookReaderT, true);
|
||||
assert.strictEqual(bookReader2.booksRead, 2);
|
||||
|
||||
var other = movie.characters[3];
|
||||
assert.strictEqual(other, "I am other");
|
||||
}
|
||||
|
||||
function createMovie(fbb) {
|
||||
Attacker.startAttacker(fbb);
|
||||
Attacker.addSwordAttackDamage(fbb, 5);
|
||||
var attackerOffset = Attacker.endAttacker(fbb);
|
||||
|
||||
var charTypesOffset = Movie.createCharactersTypeVector(fbb, charTypes);
|
||||
var charsOffset = 0;
|
||||
|
||||
let otherOffset = fbb.createString("I am other");
|
||||
|
||||
charsOffset = Movie.createCharactersVector(
|
||||
fbb,
|
||||
[
|
||||
BookReader.createBookReader(fbb, 7),
|
||||
attackerOffset,
|
||||
BookReader.createBookReader(fbb, 2),
|
||||
otherOffset
|
||||
]
|
||||
);
|
||||
|
||||
Movie.startMovie(fbb);
|
||||
Movie.addCharactersType(fbb, charTypesOffset);
|
||||
Movie.addCharacters(fbb, charsOffset);
|
||||
Movie.finishMovieBuffer(fbb, Movie.endMovie(fbb))
|
||||
}
|
||||
|
||||
function main() {
|
||||
var fbb = new flatbuffers.Builder();
|
||||
|
||||
createMovie(fbb);
|
||||
|
||||
var buf = new flatbuffers.ByteBuffer(fbb.asUint8Array());
|
||||
|
||||
var movie = Movie.getRootAsMovie(buf);
|
||||
testMovieBuf(movie);
|
||||
|
||||
testMovieUnpack(movie.unpack());
|
||||
|
||||
var movie_to = new MovieT();
|
||||
movie.unpackTo(movie_to);
|
||||
testMovieUnpack(movie_to);
|
||||
|
||||
fbb.clear();
|
||||
Movie.finishMovieBuffer(fbb, movie_to.pack(fbb));
|
||||
var unpackBuf = new flatbuffers.ByteBuffer(fbb.asUint8Array());
|
||||
testMovieBuf(Movie.getRootAsMovie(unpackBuf));
|
||||
|
||||
console.log('FlatBuffers union vector test: completed successfully');
|
||||
}
|
||||
|
||||
main();
|
||||
123
tests/ts/TypeScriptTest.py
Executable file
123
tests/ts/TypeScriptTest.py
Executable file
@@ -0,0 +1,123 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright 2022 Google Inc. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import platform
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Get the path where this script is located so we can invoke the script from
|
||||
# any directory and have the paths work correctly.
|
||||
tests_path = Path(__file__).parent.resolve()
|
||||
|
||||
# Get the root path as an absolute path, so all derived paths are absolute.
|
||||
root_path = tests_path.parent.parent.absolute()
|
||||
|
||||
# Windows works with subprocess.run a bit differently.
|
||||
is_windows = platform.system() == "Windows"
|
||||
|
||||
# Get the location of the flatc executable
|
||||
flatc_exe = Path("flatc.exe" if is_windows else "flatc")
|
||||
|
||||
# Find and assert flatc compiler is present.
|
||||
if root_path in flatc_exe.parents:
|
||||
flatc_exe = flatc_exe.relative_to(root_path)
|
||||
flatc_path = Path(root_path, flatc_exe)
|
||||
assert flatc_path.exists(), "Cannot find the flatc compiler " + str(flatc_path)
|
||||
|
||||
def check_call(args, cwd=tests_path):
|
||||
subprocess.check_call(args, cwd=str(cwd), shell=is_windows)
|
||||
|
||||
# Execute the flatc compiler with the specified parameters
|
||||
def flatc(options, schema, prefix=None, include=None, data=None, cwd=tests_path):
|
||||
cmd = [str(flatc_path)] + options
|
||||
if prefix:
|
||||
cmd += ["-o"] + [prefix]
|
||||
if include:
|
||||
cmd += ["-I"] + [include]
|
||||
cmd += [schema] if isinstance(schema, str) else schema
|
||||
if data:
|
||||
cmd += [data] if isinstance(data, str) else data
|
||||
check_call(cmd)
|
||||
|
||||
print("Removing node_modules/ directory...")
|
||||
shutil.rmtree(Path(tests_path, "node_modules"), ignore_errors=True)
|
||||
|
||||
check_call(["npm", "install", "--silent"])
|
||||
|
||||
print("Invoking flatc...")
|
||||
flatc(
|
||||
options=["--ts", "--gen-name-strings", "--gen-mutable", "--gen-object-api"],
|
||||
schema="../monster_test.fbs",
|
||||
include="../include_test",
|
||||
)
|
||||
|
||||
flatc(
|
||||
options=["--gen-object-api", "-b"],
|
||||
schema="../monster_test.fbs",
|
||||
include="../include_test",
|
||||
data="../unicode_test.json",
|
||||
)
|
||||
|
||||
flatc(
|
||||
options=["--ts", "--gen-name-strings", "--gen-mutable", "--gen-object-api"],
|
||||
schema="../union_vector/union_vector.fbs",
|
||||
prefix="union_vector",
|
||||
)
|
||||
|
||||
flatc(
|
||||
options=["--ts", "--gen-name-strings"],
|
||||
schema="../optional_scalars.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
options=["--ts", "--gen-name-strings", "--gen-mutable", "--gen-object-api"],
|
||||
schema=[
|
||||
"typescript_keywords.fbs",
|
||||
"test_dir/typescript_include.fbs",
|
||||
"test_dir/typescript_transitive_include.fbs",
|
||||
"../../reflection/reflection.fbs",
|
||||
],
|
||||
include="../../",
|
||||
)
|
||||
|
||||
flatc(
|
||||
options=[
|
||||
"--ts",
|
||||
"--gen-name-strings",
|
||||
"--gen-mutable",
|
||||
"--gen-object-api",
|
||||
"--ts-flat-files",
|
||||
],
|
||||
schema=[
|
||||
"typescript_keywords.fbs",
|
||||
"test_dir/typescript_include.fbs",
|
||||
"test_dir/typescript_transitive_include.fbs",
|
||||
"../../reflection/reflection.fbs",
|
||||
],
|
||||
include="../../",
|
||||
)
|
||||
|
||||
print("Running TypeScript Compiler...")
|
||||
check_call(["tsc"])
|
||||
|
||||
NODE_CMD = ["node"]
|
||||
|
||||
print("Running TypeScript Tests...")
|
||||
check_call(NODE_CMD + ["JavaScriptTest"])
|
||||
check_call(NODE_CMD + ["JavaScriptUnionVectorTest"])
|
||||
check_call(NODE_CMD + ["JavaScriptFlexBuffersTest"])
|
||||
5
tests/ts/foobar/abc.js
Normal file
5
tests/ts/foobar/abc.js
Normal file
@@ -0,0 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
export var Abc;
|
||||
(function (Abc) {
|
||||
Abc[Abc["a"] = 0] = "a";
|
||||
})(Abc || (Abc = {}));
|
||||
5
tests/ts/foobar/abc.ts
Normal file
5
tests/ts/foobar/abc.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export enum Abc {
|
||||
a = 0
|
||||
}
|
||||
5
tests/ts/foobar/class.js
Normal file
5
tests/ts/foobar/class.js
Normal file
@@ -0,0 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
export var class_;
|
||||
(function (class_) {
|
||||
class_[class_["arguments_"] = 0] = "arguments_";
|
||||
})(class_ || (class_ = {}));
|
||||
5
tests/ts/foobar/class.ts
Normal file
5
tests/ts/foobar/class.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export enum class_ {
|
||||
arguments_ = 0
|
||||
}
|
||||
17
tests/ts/monster_test.js
Normal file
17
tests/ts/monster_test.js
Normal file
@@ -0,0 +1,17 @@
|
||||
export { Monster as MyGameExample2Monster, MonsterT as MyGameExample2MonsterT } from './my-game/example2/monster';
|
||||
export { Ability, AbilityT } from './my-game/example/ability';
|
||||
export { Any, unionToAny, unionListToAny } from './my-game/example/any';
|
||||
export { AnyAmbiguousAliases, unionToAnyAmbiguousAliases, unionListToAnyAmbiguousAliases } from './my-game/example/any-ambiguous-aliases';
|
||||
export { AnyUniqueAliases, unionToAnyUniqueAliases, unionListToAnyUniqueAliases } from './my-game/example/any-unique-aliases';
|
||||
export { Color } from './my-game/example/color';
|
||||
export { Monster, MonsterT } from './my-game/example/monster';
|
||||
export { Race } from './my-game/example/race';
|
||||
export { Referrable, ReferrableT } from './my-game/example/referrable';
|
||||
export { Stat, StatT } from './my-game/example/stat';
|
||||
export { StructOfStructs, StructOfStructsT } from './my-game/example/struct-of-structs';
|
||||
export { StructOfStructsOfStructs, StructOfStructsOfStructsT } from './my-game/example/struct-of-structs-of-structs';
|
||||
export { Test, TestT } from './my-game/example/test';
|
||||
export { TestSimpleTableWithEnum, TestSimpleTableWithEnumT } from './my-game/example/test-simple-table-with-enum';
|
||||
export { TypeAliases, TypeAliasesT } from './my-game/example/type-aliases';
|
||||
export { Vec3, Vec3T } from './my-game/example/vec3';
|
||||
export { InParentNamespace, InParentNamespaceT } from './my-game/in-parent-namespace';
|
||||
17
tests/ts/monster_test.ts
Normal file
17
tests/ts/monster_test.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export { Monster as MyGameExample2Monster, MonsterT as MyGameExample2MonsterT } from './my-game/example2/monster';
|
||||
export { Ability, AbilityT } from './my-game/example/ability';
|
||||
export { Any, unionToAny, unionListToAny } from './my-game/example/any';
|
||||
export { AnyAmbiguousAliases, unionToAnyAmbiguousAliases, unionListToAnyAmbiguousAliases } from './my-game/example/any-ambiguous-aliases';
|
||||
export { AnyUniqueAliases, unionToAnyUniqueAliases, unionListToAnyUniqueAliases } from './my-game/example/any-unique-aliases';
|
||||
export { Color } from './my-game/example/color';
|
||||
export { Monster, MonsterT } from './my-game/example/monster';
|
||||
export { Race } from './my-game/example/race';
|
||||
export { Referrable, ReferrableT } from './my-game/example/referrable';
|
||||
export { Stat, StatT } from './my-game/example/stat';
|
||||
export { StructOfStructs, StructOfStructsT } from './my-game/example/struct-of-structs';
|
||||
export { StructOfStructsOfStructs, StructOfStructsOfStructsT } from './my-game/example/struct-of-structs-of-structs';
|
||||
export { Test, TestT } from './my-game/example/test';
|
||||
export { TestSimpleTableWithEnum, TestSimpleTableWithEnumT } from './my-game/example/test-simple-table-with-enum';
|
||||
export { TypeAliases, TypeAliasesT } from './my-game/example/type-aliases';
|
||||
export { Vec3, Vec3T } from './my-game/example/vec3';
|
||||
export { InParentNamespace, InParentNamespaceT } from './my-game/in-parent-namespace';
|
||||
19
tests/ts/monster_test_generated.ts
Normal file
19
tests/ts/monster_test_generated.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export { Monster as MyGame_Example2_Monster, MonsterT as MyGame_Example2_MonsterT } from './my-game/example2/monster.js';
|
||||
export { Ability, AbilityT } from './my-game/example/ability.js';
|
||||
export { Any, unionToAny, unionListToAny } from './my-game/example/any.js';
|
||||
export { AnyAmbiguousAliases, unionToAnyAmbiguousAliases, unionListToAnyAmbiguousAliases } from './my-game/example/any-ambiguous-aliases.js';
|
||||
export { AnyUniqueAliases, unionToAnyUniqueAliases, unionListToAnyUniqueAliases } from './my-game/example/any-unique-aliases.js';
|
||||
export { Color } from './my-game/example/color.js';
|
||||
export { Monster, MonsterT } from './my-game/example/monster.js';
|
||||
export { Race } from './my-game/example/race.js';
|
||||
export { Referrable, ReferrableT } from './my-game/example/referrable.js';
|
||||
export { Stat, StatT } from './my-game/example/stat.js';
|
||||
export { StructOfStructs, StructOfStructsT } from './my-game/example/struct-of-structs.js';
|
||||
export { StructOfStructsOfStructs, StructOfStructsOfStructsT } from './my-game/example/struct-of-structs-of-structs.js';
|
||||
export { Test, TestT } from './my-game/example/test.js';
|
||||
export { TestSimpleTableWithEnum, TestSimpleTableWithEnumT } from './my-game/example/test-simple-table-with-enum.js';
|
||||
export { TypeAliases, TypeAliasesT } from './my-game/example/type-aliases.js';
|
||||
export { Vec3, Vec3T } from './my-game/example/vec3.js';
|
||||
export { InParentNamespace, InParentNamespaceT } from './my-game/in-parent-namespace.js';
|
||||
94
tests/ts/monster_test_grpc.d.ts
vendored
Normal file
94
tests/ts/monster_test_grpc.d.ts
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
// Generated GRPC code for FlatBuffers TS *** DO NOT EDIT ***
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
import { Stat as MyGame_Example_Stat } from './my-game/example/stat';
|
||||
import { Monster as MyGame_Example_Monster } from './my-game/example/monster';
|
||||
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
|
||||
interface IMonsterStorageService extends grpc.ServiceDefinition<grpc.UntypedServiceImplementation> {
|
||||
Store: IMonsterStorageService_IStore;
|
||||
Retrieve: IMonsterStorageService_IRetrieve;
|
||||
GetMaxHitPoint: IMonsterStorageService_IGetMaxHitPoint;
|
||||
GetMinMaxHitPoints: IMonsterStorageService_IGetMinMaxHitPoints;
|
||||
}
|
||||
interface IMonsterStorageService_IStore extends grpc.MethodDefinition<MyGame_Example_Monster, MyGame_Example_Stat> {
|
||||
path: string; // /MyGame.Example.MonsterStorage/Store
|
||||
requestStream: boolean; // false
|
||||
responseStream: boolean; // false
|
||||
requestSerialize: grpc.serialize<MyGame_Example_Monster>;
|
||||
requestDeserialize: grpc.deserialize<MyGame_Example_Monster>;
|
||||
responseSerialize: grpc.serialize<MyGame_Example_Stat>;
|
||||
responseDeserialize: grpc.deserialize<MyGame_Example_Stat>;
|
||||
}
|
||||
|
||||
interface IMonsterStorageService_IRetrieve extends grpc.MethodDefinition<MyGame_Example_Stat, MyGame_Example_Monster> {
|
||||
path: string; // /MyGame.Example.MonsterStorage/Retrieve
|
||||
requestStream: boolean; // false
|
||||
responseStream: boolean; // true
|
||||
requestSerialize: grpc.serialize<MyGame_Example_Stat>;
|
||||
requestDeserialize: grpc.deserialize<MyGame_Example_Stat>;
|
||||
responseSerialize: grpc.serialize<MyGame_Example_Monster>;
|
||||
responseDeserialize: grpc.deserialize<MyGame_Example_Monster>;
|
||||
}
|
||||
|
||||
interface IMonsterStorageService_IGetMaxHitPoint extends grpc.MethodDefinition<MyGame_Example_Monster, MyGame_Example_Stat> {
|
||||
path: string; // /MyGame.Example.MonsterStorage/GetMaxHitPoint
|
||||
requestStream: boolean; // true
|
||||
responseStream: boolean; // false
|
||||
requestSerialize: grpc.serialize<MyGame_Example_Monster>;
|
||||
requestDeserialize: grpc.deserialize<MyGame_Example_Monster>;
|
||||
responseSerialize: grpc.serialize<MyGame_Example_Stat>;
|
||||
responseDeserialize: grpc.deserialize<MyGame_Example_Stat>;
|
||||
}
|
||||
|
||||
interface IMonsterStorageService_IGetMinMaxHitPoints extends grpc.MethodDefinition<MyGame_Example_Monster, MyGame_Example_Stat> {
|
||||
path: string; // /MyGame.Example.MonsterStorage/GetMinMaxHitPoints
|
||||
requestStream: boolean; // true
|
||||
responseStream: boolean; // true
|
||||
requestSerialize: grpc.serialize<MyGame_Example_Monster>;
|
||||
requestDeserialize: grpc.deserialize<MyGame_Example_Monster>;
|
||||
responseSerialize: grpc.serialize<MyGame_Example_Stat>;
|
||||
responseDeserialize: grpc.deserialize<MyGame_Example_Stat>;
|
||||
}
|
||||
|
||||
|
||||
export const MonsterStorageService: IMonsterStorageService;
|
||||
|
||||
export interface IMonsterStorageServer extends grpc.UntypedServiceImplementation {
|
||||
Store: grpc.handleUnaryCall<MyGame_Example_Monster, MyGame_Example_Stat>;
|
||||
Retrieve: grpc.handleServerStreamingCall<MyGame_Example_Stat, MyGame_Example_Monster>;
|
||||
GetMaxHitPoint: grpc.handleClientStreamingCall<MyGame_Example_Monster, MyGame_Example_Stat>;
|
||||
GetMinMaxHitPoints: grpc.handleBidiStreamingCall<MyGame_Example_Monster, MyGame_Example_Stat>;
|
||||
}
|
||||
|
||||
export interface IMonsterStorageClient {
|
||||
Store(request: MyGame_Example_Monster, callback: (error: grpc.ServiceError | null, response: MyGame_Example_Stat) => void): grpc.ClientUnaryCall;
|
||||
Store(request: MyGame_Example_Monster, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: MyGame_Example_Stat) => void): grpc.ClientUnaryCall;
|
||||
Store(request: MyGame_Example_Monster, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: MyGame_Example_Stat) => void): grpc.ClientUnaryCall;
|
||||
Retrieve(request: MyGame_Example_Stat, metadata: grpc.Metadata): grpc.ClientReadableStream<MyGame_Example_Monster>;
|
||||
Retrieve(request: MyGame_Example_Stat, options: Partial<grpc.CallOptions>): grpc.ClientReadableStream<MyGame_Example_Monster>;
|
||||
GetMaxHitPoint(callback: (error: grpc.ServiceError | null, response: MyGame_Example_Monster) => void): grpc.ClientWritableStream<MyGame_Example_Stat>;
|
||||
GetMaxHitPoint(metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: MyGame_Example_Monster) => void): grpc.ClientWritableStream<MyGame_Example_Stat>;
|
||||
GetMaxHitPoint(options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: MyGame_Example_Monster) => void): grpc.ClientWritableStream<MyGame_Example_Stat>;
|
||||
GetMaxHitPoint(metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: MyGame_Example_Monster) => void): grpc.ClientWritableStream<MyGame_Example_Stat>;
|
||||
GetMinMaxHitPoints(): grpc.ClientDuplexStream<MyGame_Example_Monster, MyGame_Example_Stat>;
|
||||
GetMinMaxHitPoints(options: Partial<grpc.CallOptions>): grpc.ClientDuplexStream<MyGame_Example_Monster, MyGame_Example_Stat>;
|
||||
GetMinMaxHitPoints(metadata: grpc.Metadata, options?: Partial<grpc.CallOptions>): grpc.ClientDuplexStream<MyGame_Example_Monster, MyGame_Example_Stat>;
|
||||
}
|
||||
|
||||
export class MonsterStorageClient extends grpc.Client implements IMonsterStorageClient {
|
||||
constructor(address: string, credentials: grpc.ChannelCredentials, options?: object);
|
||||
public Store(request: MyGame_Example_Monster, callback: (error: grpc.ServiceError | null, response: MyGame_Example_Stat) => void): grpc.ClientUnaryCall;
|
||||
public Store(request: MyGame_Example_Monster, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: MyGame_Example_Stat) => void): grpc.ClientUnaryCall;
|
||||
public Store(request: MyGame_Example_Monster, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: MyGame_Example_Stat) => void): grpc.ClientUnaryCall;
|
||||
public Retrieve(request: MyGame_Example_Stat, metadata: grpc.Metadata): grpc.ClientReadableStream<MyGame_Example_Monster>;
|
||||
public Retrieve(request: MyGame_Example_Stat, options: Partial<grpc.CallOptions>): grpc.ClientReadableStream<MyGame_Example_Monster>;
|
||||
public GetMaxHitPoint(callback: (error: grpc.ServiceError | null, response: MyGame_Example_Monster) => void): grpc.ClientWritableStream<MyGame_Example_Stat>;
|
||||
public GetMaxHitPoint(metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: MyGame_Example_Monster) => void): grpc.ClientWritableStream<MyGame_Example_Stat>;
|
||||
public GetMaxHitPoint(options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: MyGame_Example_Monster) => void): grpc.ClientWritableStream<MyGame_Example_Stat>;
|
||||
public GetMaxHitPoint(metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: MyGame_Example_Monster) => void): grpc.ClientWritableStream<MyGame_Example_Stat>;
|
||||
public GetMinMaxHitPoints(): grpc.ClientDuplexStream<MyGame_Example_Monster, MyGame_Example_Stat>;
|
||||
public GetMinMaxHitPoints(options: Partial<grpc.CallOptions>): grpc.ClientDuplexStream<MyGame_Example_Monster, MyGame_Example_Stat>;
|
||||
public GetMinMaxHitPoints(metadata: grpc.Metadata, options?: Partial<grpc.CallOptions>): grpc.ClientDuplexStream<MyGame_Example_Monster, MyGame_Example_Stat>;
|
||||
}
|
||||
|
||||
80
tests/ts/monster_test_grpc.js
Normal file
80
tests/ts/monster_test_grpc.js
Normal file
@@ -0,0 +1,80 @@
|
||||
// Generated GRPC code for FlatBuffers TS *** DO NOT EDIT ***
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
import { Stat as MyGame_Example_Stat } from './my-game/example/stat';
|
||||
import { Monster as MyGame_Example_Monster } from './my-game/example/monster';
|
||||
|
||||
var grpc = require('@grpc/grpc-js');
|
||||
|
||||
function serialize_MyGame_Example_Stat(buffer_args) {
|
||||
if (!(buffer_args instanceof MyGame_Example_Stat)) {
|
||||
throw new Error('Expected argument of type Stat');
|
||||
}
|
||||
return Buffer.from(buffer_args.serialize());
|
||||
}
|
||||
|
||||
function deserialize_MyGame_Example_Stat(buffer) {
|
||||
return MyGame_Example_Stat.getRootAsStat(new flatbuffers.ByteBuffer(buffer))
|
||||
}
|
||||
|
||||
|
||||
function serialize_MyGame_Example_Monster(buffer_args) {
|
||||
if (!(buffer_args instanceof MyGame_Example_Monster)) {
|
||||
throw new Error('Expected argument of type Monster');
|
||||
}
|
||||
return Buffer.from(buffer_args.serialize());
|
||||
}
|
||||
|
||||
function deserialize_MyGame_Example_Monster(buffer) {
|
||||
return MyGame_Example_Monster.getRootAsMonster(new flatbuffers.ByteBuffer(buffer))
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var MonsterStorageService = exports.MonsterStorageService = {
|
||||
Store: {
|
||||
path: '/MyGame.Example.MonsterStorage/Store',
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
requestType: flatbuffers.ByteBuffer,
|
||||
responseType: MyGame_Example_Stat,
|
||||
requestSerialize: serialize_MyGame_Example_Monster,
|
||||
requestDeserialize: deserialize_MyGame_Example_Monster,
|
||||
responseSerialize: serialize_MyGame_Example_Stat,
|
||||
responseDeserialize: deserialize_MyGame_Example_Stat,
|
||||
},
|
||||
Retrieve: {
|
||||
path: '/MyGame.Example.MonsterStorage/Retrieve',
|
||||
requestStream: false,
|
||||
responseStream: true,
|
||||
requestType: flatbuffers.ByteBuffer,
|
||||
responseType: MyGame_Example_Monster,
|
||||
requestSerialize: serialize_MyGame_Example_Stat,
|
||||
requestDeserialize: deserialize_MyGame_Example_Stat,
|
||||
responseSerialize: serialize_MyGame_Example_Monster,
|
||||
responseDeserialize: deserialize_MyGame_Example_Monster,
|
||||
},
|
||||
GetMaxHitPoint: {
|
||||
path: '/MyGame.Example.MonsterStorage/GetMaxHitPoint',
|
||||
requestStream: true,
|
||||
responseStream: false,
|
||||
requestType: flatbuffers.ByteBuffer,
|
||||
responseType: MyGame_Example_Stat,
|
||||
requestSerialize: serialize_MyGame_Example_Monster,
|
||||
requestDeserialize: deserialize_MyGame_Example_Monster,
|
||||
responseSerialize: serialize_MyGame_Example_Stat,
|
||||
responseDeserialize: deserialize_MyGame_Example_Stat,
|
||||
},
|
||||
GetMinMaxHitPoints: {
|
||||
path: '/MyGame.Example.MonsterStorage/GetMinMaxHitPoints',
|
||||
requestStream: true,
|
||||
responseStream: true,
|
||||
requestType: flatbuffers.ByteBuffer,
|
||||
responseType: MyGame_Example_Stat,
|
||||
requestSerialize: serialize_MyGame_Example_Monster,
|
||||
requestDeserialize: deserialize_MyGame_Example_Monster,
|
||||
responseSerialize: serialize_MyGame_Example_Stat,
|
||||
responseDeserialize: deserialize_MyGame_Example_Stat,
|
||||
},
|
||||
};
|
||||
exports.MonsterStorageClient = grpc.makeGenericClientConstructor(MonsterStorageService);
|
||||
BIN
tests/ts/monsterdata_javascript_wire.mon
Normal file
BIN
tests/ts/monsterdata_javascript_wire.mon
Normal file
Binary file not shown.
54
tests/ts/my-game/example/ability.js
Normal file
54
tests/ts/my-game/example/ability.js
Normal file
@@ -0,0 +1,54 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
export class Ability {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
id() {
|
||||
return this.bb.readUint32(this.bb_pos);
|
||||
}
|
||||
mutate_id(value) {
|
||||
this.bb.writeUint32(this.bb_pos + 0, value);
|
||||
return true;
|
||||
}
|
||||
distance() {
|
||||
return this.bb.readUint32(this.bb_pos + 4);
|
||||
}
|
||||
mutate_distance(value) {
|
||||
this.bb.writeUint32(this.bb_pos + 4, value);
|
||||
return true;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'MyGame_Example_Ability';
|
||||
}
|
||||
static sizeOf() {
|
||||
return 8;
|
||||
}
|
||||
static createAbility(builder, id, distance) {
|
||||
builder.prep(4, 8);
|
||||
builder.writeInt32(distance);
|
||||
builder.writeInt32(id);
|
||||
return builder.offset();
|
||||
}
|
||||
unpack() {
|
||||
return new AbilityT(this.id(), this.distance());
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.id = this.id();
|
||||
_o.distance = this.distance();
|
||||
}
|
||||
}
|
||||
export class AbilityT {
|
||||
constructor(id = 0, distance = 0) {
|
||||
this.id = id;
|
||||
this.distance = distance;
|
||||
}
|
||||
pack(builder) {
|
||||
return Ability.createAbility(builder, this.id, this.distance);
|
||||
}
|
||||
}
|
||||
77
tests/ts/my-game/example/ability.ts
Normal file
77
tests/ts/my-game/example/ability.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
export class Ability {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Ability {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
id():number {
|
||||
return this.bb!.readUint32(this.bb_pos);
|
||||
}
|
||||
|
||||
mutate_id(value:number):boolean {
|
||||
this.bb!.writeUint32(this.bb_pos + 0, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
distance():number {
|
||||
return this.bb!.readUint32(this.bb_pos + 4);
|
||||
}
|
||||
|
||||
mutate_distance(value:number):boolean {
|
||||
this.bb!.writeUint32(this.bb_pos + 4, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'MyGame_Example_Ability';
|
||||
}
|
||||
|
||||
static sizeOf():number {
|
||||
return 8;
|
||||
}
|
||||
|
||||
static createAbility(builder:flatbuffers.Builder, id: number, distance: number):flatbuffers.Offset {
|
||||
builder.prep(4, 8);
|
||||
builder.writeInt32(distance);
|
||||
builder.writeInt32(id);
|
||||
return builder.offset();
|
||||
}
|
||||
|
||||
|
||||
unpack(): AbilityT {
|
||||
return new AbilityT(
|
||||
this.id(),
|
||||
this.distance()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: AbilityT): void {
|
||||
_o.id = this.id();
|
||||
_o.distance = this.distance();
|
||||
}
|
||||
}
|
||||
|
||||
export class AbilityT {
|
||||
constructor(
|
||||
public id: number = 0,
|
||||
public distance: number = 0
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return Ability.createAbility(builder,
|
||||
this.id,
|
||||
this.distance
|
||||
);
|
||||
}
|
||||
}
|
||||
27
tests/ts/my-game/example/any-ambiguous-aliases.js
Normal file
27
tests/ts/my-game/example/any-ambiguous-aliases.js
Normal file
@@ -0,0 +1,27 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import { Monster } from '../../my-game/example/monster.js';
|
||||
export var AnyAmbiguousAliases;
|
||||
(function (AnyAmbiguousAliases) {
|
||||
AnyAmbiguousAliases[AnyAmbiguousAliases["NONE"] = 0] = "NONE";
|
||||
AnyAmbiguousAliases[AnyAmbiguousAliases["M1"] = 1] = "M1";
|
||||
AnyAmbiguousAliases[AnyAmbiguousAliases["M2"] = 2] = "M2";
|
||||
AnyAmbiguousAliases[AnyAmbiguousAliases["M3"] = 3] = "M3";
|
||||
})(AnyAmbiguousAliases || (AnyAmbiguousAliases = {}));
|
||||
export function unionToAnyAmbiguousAliases(type, accessor) {
|
||||
switch (AnyAmbiguousAliases[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'M1': return accessor(new Monster());
|
||||
case 'M2': return accessor(new Monster());
|
||||
case 'M3': return accessor(new Monster());
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
export function unionListToAnyAmbiguousAliases(type, accessor, index) {
|
||||
switch (AnyAmbiguousAliases[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'M1': return accessor(index, new Monster());
|
||||
case 'M2': return accessor(index, new Monster());
|
||||
case 'M3': return accessor(index, new Monster());
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
38
tests/ts/my-game/example/any-ambiguous-aliases.ts
Normal file
38
tests/ts/my-game/example/any-ambiguous-aliases.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import { Monster, MonsterT } from '../../my-game/example/monster.js';
|
||||
|
||||
|
||||
export enum AnyAmbiguousAliases {
|
||||
NONE = 0,
|
||||
M1 = 1,
|
||||
M2 = 2,
|
||||
M3 = 3
|
||||
}
|
||||
|
||||
export function unionToAnyAmbiguousAliases(
|
||||
type: AnyAmbiguousAliases,
|
||||
accessor: (obj:Monster) => Monster|null
|
||||
): Monster|null {
|
||||
switch(AnyAmbiguousAliases[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'M1': return accessor(new Monster())! as Monster;
|
||||
case 'M2': return accessor(new Monster())! as Monster;
|
||||
case 'M3': return accessor(new Monster())! as Monster;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function unionListToAnyAmbiguousAliases(
|
||||
type: AnyAmbiguousAliases,
|
||||
accessor: (index: number, obj:Monster) => Monster|null,
|
||||
index: number
|
||||
): Monster|null {
|
||||
switch(AnyAmbiguousAliases[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'M1': return accessor(index, new Monster())! as Monster;
|
||||
case 'M2': return accessor(index, new Monster())! as Monster;
|
||||
case 'M3': return accessor(index, new Monster())! as Monster;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
29
tests/ts/my-game/example/any-unique-aliases.js
Normal file
29
tests/ts/my-game/example/any-unique-aliases.js
Normal file
@@ -0,0 +1,29 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import { Monster as MyGame_Example2_Monster } from '../../my-game/example2/monster.js';
|
||||
import { Monster } from '../../my-game/example/monster.js';
|
||||
import { TestSimpleTableWithEnum } from '../../my-game/example/test-simple-table-with-enum.js';
|
||||
export var AnyUniqueAliases;
|
||||
(function (AnyUniqueAliases) {
|
||||
AnyUniqueAliases[AnyUniqueAliases["NONE"] = 0] = "NONE";
|
||||
AnyUniqueAliases[AnyUniqueAliases["M"] = 1] = "M";
|
||||
AnyUniqueAliases[AnyUniqueAliases["TS"] = 2] = "TS";
|
||||
AnyUniqueAliases[AnyUniqueAliases["M2"] = 3] = "M2";
|
||||
})(AnyUniqueAliases || (AnyUniqueAliases = {}));
|
||||
export function unionToAnyUniqueAliases(type, accessor) {
|
||||
switch (AnyUniqueAliases[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'M': return accessor(new Monster());
|
||||
case 'TS': return accessor(new TestSimpleTableWithEnum());
|
||||
case 'M2': return accessor(new MyGame_Example2_Monster());
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
export function unionListToAnyUniqueAliases(type, accessor, index) {
|
||||
switch (AnyUniqueAliases[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'M': return accessor(index, new Monster());
|
||||
case 'TS': return accessor(index, new TestSimpleTableWithEnum());
|
||||
case 'M2': return accessor(index, new MyGame_Example2_Monster());
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
40
tests/ts/my-game/example/any-unique-aliases.ts
Normal file
40
tests/ts/my-game/example/any-unique-aliases.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import { Monster as MyGame_Example2_Monster, MonsterT as MyGame_Example2_MonsterT } from '../../my-game/example2/monster.js';
|
||||
import { Monster, MonsterT } from '../../my-game/example/monster.js';
|
||||
import { TestSimpleTableWithEnum, TestSimpleTableWithEnumT } from '../../my-game/example/test-simple-table-with-enum.js';
|
||||
|
||||
|
||||
export enum AnyUniqueAliases {
|
||||
NONE = 0,
|
||||
M = 1,
|
||||
TS = 2,
|
||||
M2 = 3
|
||||
}
|
||||
|
||||
export function unionToAnyUniqueAliases(
|
||||
type: AnyUniqueAliases,
|
||||
accessor: (obj:Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum) => Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum|null
|
||||
): Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum|null {
|
||||
switch(AnyUniqueAliases[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'M': return accessor(new Monster())! as Monster;
|
||||
case 'TS': return accessor(new TestSimpleTableWithEnum())! as TestSimpleTableWithEnum;
|
||||
case 'M2': return accessor(new MyGame_Example2_Monster())! as MyGame_Example2_Monster;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function unionListToAnyUniqueAliases(
|
||||
type: AnyUniqueAliases,
|
||||
accessor: (index: number, obj:Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum) => Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum|null,
|
||||
index: number
|
||||
): Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum|null {
|
||||
switch(AnyUniqueAliases[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'M': return accessor(index, new Monster())! as Monster;
|
||||
case 'TS': return accessor(index, new TestSimpleTableWithEnum())! as TestSimpleTableWithEnum;
|
||||
case 'M2': return accessor(index, new MyGame_Example2_Monster())! as MyGame_Example2_Monster;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
29
tests/ts/my-game/example/any.js
Normal file
29
tests/ts/my-game/example/any.js
Normal file
@@ -0,0 +1,29 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import { Monster as MyGame_Example2_Monster } from '../../my-game/example2/monster.js';
|
||||
import { Monster } from '../../my-game/example/monster.js';
|
||||
import { TestSimpleTableWithEnum } from '../../my-game/example/test-simple-table-with-enum.js';
|
||||
export var Any;
|
||||
(function (Any) {
|
||||
Any[Any["NONE"] = 0] = "NONE";
|
||||
Any[Any["Monster"] = 1] = "Monster";
|
||||
Any[Any["TestSimpleTableWithEnum"] = 2] = "TestSimpleTableWithEnum";
|
||||
Any[Any["MyGame_Example2_Monster"] = 3] = "MyGame_Example2_Monster";
|
||||
})(Any || (Any = {}));
|
||||
export function unionToAny(type, accessor) {
|
||||
switch (Any[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'Monster': return accessor(new Monster());
|
||||
case 'TestSimpleTableWithEnum': return accessor(new TestSimpleTableWithEnum());
|
||||
case 'MyGame_Example2_Monster': return accessor(new MyGame_Example2_Monster());
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
export function unionListToAny(type, accessor, index) {
|
||||
switch (Any[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'Monster': return accessor(index, new Monster());
|
||||
case 'TestSimpleTableWithEnum': return accessor(index, new TestSimpleTableWithEnum());
|
||||
case 'MyGame_Example2_Monster': return accessor(index, new MyGame_Example2_Monster());
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
40
tests/ts/my-game/example/any.ts
Normal file
40
tests/ts/my-game/example/any.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import { Monster as MyGame_Example2_Monster, MonsterT as MyGame_Example2_MonsterT } from '../../my-game/example2/monster.js';
|
||||
import { Monster, MonsterT } from '../../my-game/example/monster.js';
|
||||
import { TestSimpleTableWithEnum, TestSimpleTableWithEnumT } from '../../my-game/example/test-simple-table-with-enum.js';
|
||||
|
||||
|
||||
export enum Any {
|
||||
NONE = 0,
|
||||
Monster = 1,
|
||||
TestSimpleTableWithEnum = 2,
|
||||
MyGame_Example2_Monster = 3
|
||||
}
|
||||
|
||||
export function unionToAny(
|
||||
type: Any,
|
||||
accessor: (obj:Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum) => Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum|null
|
||||
): Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum|null {
|
||||
switch(Any[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'Monster': return accessor(new Monster())! as Monster;
|
||||
case 'TestSimpleTableWithEnum': return accessor(new TestSimpleTableWithEnum())! as TestSimpleTableWithEnum;
|
||||
case 'MyGame_Example2_Monster': return accessor(new MyGame_Example2_Monster())! as MyGame_Example2_Monster;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function unionListToAny(
|
||||
type: Any,
|
||||
accessor: (index: number, obj:Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum) => Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum|null,
|
||||
index: number
|
||||
): Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum|null {
|
||||
switch(Any[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'Monster': return accessor(index, new Monster())! as Monster;
|
||||
case 'TestSimpleTableWithEnum': return accessor(index, new TestSimpleTableWithEnum())! as TestSimpleTableWithEnum;
|
||||
case 'MyGame_Example2_Monster': return accessor(index, new MyGame_Example2_Monster())! as MyGame_Example2_Monster;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
17
tests/ts/my-game/example/color.js
Normal file
17
tests/ts/my-game/example/color.js
Normal file
@@ -0,0 +1,17 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
/**
|
||||
* Composite components of Monster color.
|
||||
*/
|
||||
export var Color;
|
||||
(function (Color) {
|
||||
Color[Color["Red"] = 1] = "Red";
|
||||
/**
|
||||
* \brief color Green
|
||||
* Green is bit_flag with value (1u << 1)
|
||||
*/
|
||||
Color[Color["Green"] = 2] = "Green";
|
||||
/**
|
||||
* \brief color Blue (1u << 3)
|
||||
*/
|
||||
Color[Color["Blue"] = 8] = "Blue";
|
||||
})(Color || (Color = {}));
|
||||
19
tests/ts/my-game/example/color.ts
Normal file
19
tests/ts/my-game/example/color.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/**
|
||||
* Composite components of Monster color.
|
||||
*/
|
||||
export enum Color {
|
||||
Red = 1,
|
||||
|
||||
/**
|
||||
* \brief color Green
|
||||
* Green is bit_flag with value (1u << 1)
|
||||
*/
|
||||
Green = 2,
|
||||
|
||||
/**
|
||||
* \brief color Blue (1u << 3)
|
||||
*/
|
||||
Blue = 8
|
||||
}
|
||||
7
tests/ts/my-game/example/long-enum.js
Normal file
7
tests/ts/my-game/example/long-enum.js
Normal file
@@ -0,0 +1,7 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
export var LongEnum;
|
||||
(function (LongEnum) {
|
||||
LongEnum["LongOne"] = "2";
|
||||
LongEnum["LongTwo"] = "4";
|
||||
LongEnum["LongBig"] = "1099511627776";
|
||||
})(LongEnum || (LongEnum = {}));
|
||||
7
tests/ts/my-game/example/long-enum.ts
Normal file
7
tests/ts/my-game/example/long-enum.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export enum LongEnum {
|
||||
LongOne = '2',
|
||||
LongTwo = '4',
|
||||
LongBig = '1099511627776'
|
||||
}
|
||||
1125
tests/ts/my-game/example/monster.js
Normal file
1125
tests/ts/my-game/example/monster.js
Normal file
File diff suppressed because it is too large
Load Diff
1434
tests/ts/my-game/example/monster.ts
Normal file
1434
tests/ts/my-game/example/monster.ts
Normal file
File diff suppressed because it is too large
Load Diff
8
tests/ts/my-game/example/race.js
Normal file
8
tests/ts/my-game/example/race.js
Normal file
@@ -0,0 +1,8 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
export var Race;
|
||||
(function (Race) {
|
||||
Race[Race["None"] = -1] = "None";
|
||||
Race[Race["Human"] = 0] = "Human";
|
||||
Race[Race["Dwarf"] = 1] = "Dwarf";
|
||||
Race[Race["Elf"] = 2] = "Elf";
|
||||
})(Race || (Race = {}));
|
||||
8
tests/ts/my-game/example/race.ts
Normal file
8
tests/ts/my-game/example/race.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export enum Race {
|
||||
None = -1,
|
||||
Human = 0,
|
||||
Dwarf = 1,
|
||||
Elf = 2
|
||||
}
|
||||
70
tests/ts/my-game/example/referrable.js
Normal file
70
tests/ts/my-game/example/referrable.js
Normal file
@@ -0,0 +1,70 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
export class Referrable {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsReferrable(bb, obj) {
|
||||
return (obj || new Referrable()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsReferrable(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Referrable()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
id() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
mutate_id(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeUint64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'MyGame_Example_Referrable';
|
||||
}
|
||||
static startReferrable(builder) {
|
||||
builder.startObject(1);
|
||||
}
|
||||
static addId(builder, id) {
|
||||
builder.addFieldInt64(0, id, BigInt('0'));
|
||||
}
|
||||
static endReferrable(builder) {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
static createReferrable(builder, id) {
|
||||
Referrable.startReferrable(builder);
|
||||
Referrable.addId(builder, id);
|
||||
return Referrable.endReferrable(builder);
|
||||
}
|
||||
serialize() {
|
||||
return this.bb.bytes();
|
||||
}
|
||||
static deserialize(buffer) {
|
||||
return Referrable.getRootAsReferrable(new flatbuffers.ByteBuffer(buffer));
|
||||
}
|
||||
unpack() {
|
||||
return new ReferrableT(this.id());
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.id = this.id();
|
||||
}
|
||||
}
|
||||
export class ReferrableT {
|
||||
constructor(id = BigInt('0')) {
|
||||
this.id = id;
|
||||
}
|
||||
pack(builder) {
|
||||
return Referrable.createReferrable(builder, this.id);
|
||||
}
|
||||
}
|
||||
95
tests/ts/my-game/example/referrable.ts
Normal file
95
tests/ts/my-game/example/referrable.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
export class Referrable {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Referrable {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsReferrable(bb:flatbuffers.ByteBuffer, obj?:Referrable):Referrable {
|
||||
return (obj || new Referrable()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsReferrable(bb:flatbuffers.ByteBuffer, obj?:Referrable):Referrable {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Referrable()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
id():bigint {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
|
||||
mutate_id(value:bigint):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeUint64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'MyGame_Example_Referrable';
|
||||
}
|
||||
|
||||
static startReferrable(builder:flatbuffers.Builder) {
|
||||
builder.startObject(1);
|
||||
}
|
||||
|
||||
static addId(builder:flatbuffers.Builder, id:bigint) {
|
||||
builder.addFieldInt64(0, id, BigInt('0'));
|
||||
}
|
||||
|
||||
static endReferrable(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createReferrable(builder:flatbuffers.Builder, id:bigint):flatbuffers.Offset {
|
||||
Referrable.startReferrable(builder);
|
||||
Referrable.addId(builder, id);
|
||||
return Referrable.endReferrable(builder);
|
||||
}
|
||||
|
||||
serialize():Uint8Array {
|
||||
return this.bb!.bytes();
|
||||
}
|
||||
|
||||
static deserialize(buffer: Uint8Array):Referrable {
|
||||
return Referrable.getRootAsReferrable(new flatbuffers.ByteBuffer(buffer))
|
||||
}
|
||||
|
||||
unpack(): ReferrableT {
|
||||
return new ReferrableT(
|
||||
this.id()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: ReferrableT): void {
|
||||
_o.id = this.id();
|
||||
}
|
||||
}
|
||||
|
||||
export class ReferrableT {
|
||||
constructor(
|
||||
public id: bigint = BigInt('0')
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return Referrable.createReferrable(builder,
|
||||
this.id
|
||||
);
|
||||
}
|
||||
}
|
||||
99
tests/ts/my-game/example/stat.js
Normal file
99
tests/ts/my-game/example/stat.js
Normal file
@@ -0,0 +1,99 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
export class Stat {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsStat(bb, obj) {
|
||||
return (obj || new Stat()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsStat(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Stat()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
id(optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
val() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
mutate_val(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
count() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb.readUint16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_count(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeUint16(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'MyGame_Example_Stat';
|
||||
}
|
||||
static startStat(builder) {
|
||||
builder.startObject(3);
|
||||
}
|
||||
static addId(builder, idOffset) {
|
||||
builder.addFieldOffset(0, idOffset, 0);
|
||||
}
|
||||
static addVal(builder, val) {
|
||||
builder.addFieldInt64(1, val, BigInt('0'));
|
||||
}
|
||||
static addCount(builder, count) {
|
||||
builder.addFieldInt16(2, count, 0);
|
||||
}
|
||||
static endStat(builder) {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
static createStat(builder, idOffset, val, count) {
|
||||
Stat.startStat(builder);
|
||||
Stat.addId(builder, idOffset);
|
||||
Stat.addVal(builder, val);
|
||||
Stat.addCount(builder, count);
|
||||
return Stat.endStat(builder);
|
||||
}
|
||||
serialize() {
|
||||
return this.bb.bytes();
|
||||
}
|
||||
static deserialize(buffer) {
|
||||
return Stat.getRootAsStat(new flatbuffers.ByteBuffer(buffer));
|
||||
}
|
||||
unpack() {
|
||||
return new StatT(this.id(), this.val(), this.count());
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.id = this.id();
|
||||
_o.val = this.val();
|
||||
_o.count = this.count();
|
||||
}
|
||||
}
|
||||
export class StatT {
|
||||
constructor(id = null, val = BigInt('0'), count = 0) {
|
||||
this.id = id;
|
||||
this.val = val;
|
||||
this.count = count;
|
||||
}
|
||||
pack(builder) {
|
||||
const id = (this.id !== null ? builder.createString(this.id) : 0);
|
||||
return Stat.createStat(builder, id, this.val, this.count);
|
||||
}
|
||||
}
|
||||
138
tests/ts/my-game/example/stat.ts
Normal file
138
tests/ts/my-game/example/stat.ts
Normal file
@@ -0,0 +1,138 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
export class Stat {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Stat {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsStat(bb:flatbuffers.ByteBuffer, obj?:Stat):Stat {
|
||||
return (obj || new Stat()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsStat(bb:flatbuffers.ByteBuffer, obj?:Stat):Stat {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Stat()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
id():string|null
|
||||
id(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||
id(optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
val():bigint {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
|
||||
mutate_val(value:bigint):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
count():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_count(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeUint16(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'MyGame_Example_Stat';
|
||||
}
|
||||
|
||||
static startStat(builder:flatbuffers.Builder) {
|
||||
builder.startObject(3);
|
||||
}
|
||||
|
||||
static addId(builder:flatbuffers.Builder, idOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(0, idOffset, 0);
|
||||
}
|
||||
|
||||
static addVal(builder:flatbuffers.Builder, val:bigint) {
|
||||
builder.addFieldInt64(1, val, BigInt('0'));
|
||||
}
|
||||
|
||||
static addCount(builder:flatbuffers.Builder, count:number) {
|
||||
builder.addFieldInt16(2, count, 0);
|
||||
}
|
||||
|
||||
static endStat(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createStat(builder:flatbuffers.Builder, idOffset:flatbuffers.Offset, val:bigint, count:number):flatbuffers.Offset {
|
||||
Stat.startStat(builder);
|
||||
Stat.addId(builder, idOffset);
|
||||
Stat.addVal(builder, val);
|
||||
Stat.addCount(builder, count);
|
||||
return Stat.endStat(builder);
|
||||
}
|
||||
|
||||
serialize():Uint8Array {
|
||||
return this.bb!.bytes();
|
||||
}
|
||||
|
||||
static deserialize(buffer: Uint8Array):Stat {
|
||||
return Stat.getRootAsStat(new flatbuffers.ByteBuffer(buffer))
|
||||
}
|
||||
|
||||
unpack(): StatT {
|
||||
return new StatT(
|
||||
this.id(),
|
||||
this.val(),
|
||||
this.count()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: StatT): void {
|
||||
_o.id = this.id();
|
||||
_o.val = this.val();
|
||||
_o.count = this.count();
|
||||
}
|
||||
}
|
||||
|
||||
export class StatT {
|
||||
constructor(
|
||||
public id: string|Uint8Array|null = null,
|
||||
public val: bigint = BigInt('0'),
|
||||
public count: number = 0
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const id = (this.id !== null ? builder.createString(this.id!) : 0);
|
||||
|
||||
return Stat.createStat(builder,
|
||||
id,
|
||||
this.val,
|
||||
this.count
|
||||
);
|
||||
}
|
||||
}
|
||||
52
tests/ts/my-game/example/struct-of-structs-of-structs.js
Normal file
52
tests/ts/my-game/example/struct-of-structs-of-structs.js
Normal file
@@ -0,0 +1,52 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import { StructOfStructs } from '../../my-game/example/struct-of-structs.js';
|
||||
export class StructOfStructsOfStructs {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
a(obj) {
|
||||
return (obj || new StructOfStructs()).__init(this.bb_pos, this.bb);
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'MyGame_Example_StructOfStructsOfStructs';
|
||||
}
|
||||
static sizeOf() {
|
||||
return 20;
|
||||
}
|
||||
static createStructOfStructsOfStructs(builder, a_a_id, a_a_distance, a_b_a, a_b_b, a_c_id, a_c_distance) {
|
||||
builder.prep(4, 20);
|
||||
builder.prep(4, 20);
|
||||
builder.prep(4, 8);
|
||||
builder.writeInt32(a_c_distance);
|
||||
builder.writeInt32(a_c_id);
|
||||
builder.prep(2, 4);
|
||||
builder.pad(1);
|
||||
builder.writeInt8(a_b_b);
|
||||
builder.writeInt16(a_b_a);
|
||||
builder.prep(4, 8);
|
||||
builder.writeInt32(a_a_distance);
|
||||
builder.writeInt32(a_a_id);
|
||||
return builder.offset();
|
||||
}
|
||||
unpack() {
|
||||
return new StructOfStructsOfStructsT((this.a() !== null ? this.a().unpack() : null));
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.a = (this.a() !== null ? this.a().unpack() : null);
|
||||
}
|
||||
}
|
||||
export class StructOfStructsOfStructsT {
|
||||
constructor(a = null) {
|
||||
this.a = a;
|
||||
}
|
||||
pack(builder) {
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _p, _q, _r, _s, _t, _u;
|
||||
return StructOfStructsOfStructs.createStructOfStructsOfStructs(builder, ((_c = (_b = (_a = this.a) === null || _a === void 0 ? void 0 : _a.a) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : 0), ((_f = (_e = (_d = this.a) === null || _d === void 0 ? void 0 : _d.a) === null || _e === void 0 ? void 0 : _e.distance) !== null && _f !== void 0 ? _f : 0), ((_j = (_h = (_g = this.a) === null || _g === void 0 ? void 0 : _g.b) === null || _h === void 0 ? void 0 : _h.a) !== null && _j !== void 0 ? _j : 0), ((_m = (_l = (_k = this.a) === null || _k === void 0 ? void 0 : _k.b) === null || _l === void 0 ? void 0 : _l.b) !== null && _m !== void 0 ? _m : 0), ((_r = (_q = (_p = this.a) === null || _p === void 0 ? void 0 : _p.c) === null || _q === void 0 ? void 0 : _q.id) !== null && _r !== void 0 ? _r : 0), ((_u = (_t = (_s = this.a) === null || _s === void 0 ? void 0 : _s.c) === null || _t === void 0 ? void 0 : _t.distance) !== null && _u !== void 0 ? _u : 0));
|
||||
}
|
||||
}
|
||||
74
tests/ts/my-game/example/struct-of-structs-of-structs.ts
Normal file
74
tests/ts/my-game/example/struct-of-structs-of-structs.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { StructOfStructs, StructOfStructsT } from '../../my-game/example/struct-of-structs.js';
|
||||
|
||||
|
||||
export class StructOfStructsOfStructs {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):StructOfStructsOfStructs {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
a(obj?:StructOfStructs):StructOfStructs|null {
|
||||
return (obj || new StructOfStructs()).__init(this.bb_pos, this.bb!);
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'MyGame_Example_StructOfStructsOfStructs';
|
||||
}
|
||||
|
||||
static sizeOf():number {
|
||||
return 20;
|
||||
}
|
||||
|
||||
static createStructOfStructsOfStructs(builder:flatbuffers.Builder, a_a_id: number, a_a_distance: number, a_b_a: number, a_b_b: number, a_c_id: number, a_c_distance: number):flatbuffers.Offset {
|
||||
builder.prep(4, 20);
|
||||
builder.prep(4, 20);
|
||||
builder.prep(4, 8);
|
||||
builder.writeInt32(a_c_distance);
|
||||
builder.writeInt32(a_c_id);
|
||||
builder.prep(2, 4);
|
||||
builder.pad(1);
|
||||
builder.writeInt8(a_b_b);
|
||||
builder.writeInt16(a_b_a);
|
||||
builder.prep(4, 8);
|
||||
builder.writeInt32(a_a_distance);
|
||||
builder.writeInt32(a_a_id);
|
||||
return builder.offset();
|
||||
}
|
||||
|
||||
|
||||
unpack(): StructOfStructsOfStructsT {
|
||||
return new StructOfStructsOfStructsT(
|
||||
(this.a() !== null ? this.a()!.unpack() : null)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: StructOfStructsOfStructsT): void {
|
||||
_o.a = (this.a() !== null ? this.a()!.unpack() : null);
|
||||
}
|
||||
}
|
||||
|
||||
export class StructOfStructsOfStructsT {
|
||||
constructor(
|
||||
public a: StructOfStructsT|null = null
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return StructOfStructsOfStructs.createStructOfStructsOfStructs(builder,
|
||||
(this.a?.a?.id ?? 0),
|
||||
(this.a?.a?.distance ?? 0),
|
||||
(this.a?.b?.a ?? 0),
|
||||
(this.a?.b?.b ?? 0),
|
||||
(this.a?.c?.id ?? 0),
|
||||
(this.a?.c?.distance ?? 0)
|
||||
);
|
||||
}
|
||||
}
|
||||
62
tests/ts/my-game/example/struct-of-structs.js
Normal file
62
tests/ts/my-game/example/struct-of-structs.js
Normal file
@@ -0,0 +1,62 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import { Ability } from '../../my-game/example/ability.js';
|
||||
import { Test } from '../../my-game/example/test.js';
|
||||
export class StructOfStructs {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
a(obj) {
|
||||
return (obj || new Ability()).__init(this.bb_pos, this.bb);
|
||||
}
|
||||
b(obj) {
|
||||
return (obj || new Test()).__init(this.bb_pos + 8, this.bb);
|
||||
}
|
||||
c(obj) {
|
||||
return (obj || new Ability()).__init(this.bb_pos + 12, this.bb);
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'MyGame_Example_StructOfStructs';
|
||||
}
|
||||
static sizeOf() {
|
||||
return 20;
|
||||
}
|
||||
static createStructOfStructs(builder, a_id, a_distance, b_a, b_b, c_id, c_distance) {
|
||||
builder.prep(4, 20);
|
||||
builder.prep(4, 8);
|
||||
builder.writeInt32(c_distance);
|
||||
builder.writeInt32(c_id);
|
||||
builder.prep(2, 4);
|
||||
builder.pad(1);
|
||||
builder.writeInt8(b_b);
|
||||
builder.writeInt16(b_a);
|
||||
builder.prep(4, 8);
|
||||
builder.writeInt32(a_distance);
|
||||
builder.writeInt32(a_id);
|
||||
return builder.offset();
|
||||
}
|
||||
unpack() {
|
||||
return new StructOfStructsT((this.a() !== null ? this.a().unpack() : null), (this.b() !== null ? this.b().unpack() : null), (this.c() !== null ? this.c().unpack() : null));
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.a = (this.a() !== null ? this.a().unpack() : null);
|
||||
_o.b = (this.b() !== null ? this.b().unpack() : null);
|
||||
_o.c = (this.c() !== null ? this.c().unpack() : null);
|
||||
}
|
||||
}
|
||||
export class StructOfStructsT {
|
||||
constructor(a = null, b = null, c = null) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
}
|
||||
pack(builder) {
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
||||
return StructOfStructs.createStructOfStructs(builder, ((_b = (_a = this.a) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : 0), ((_d = (_c = this.a) === null || _c === void 0 ? void 0 : _c.distance) !== null && _d !== void 0 ? _d : 0), ((_f = (_e = this.b) === null || _e === void 0 ? void 0 : _e.a) !== null && _f !== void 0 ? _f : 0), ((_h = (_g = this.b) === null || _g === void 0 ? void 0 : _g.b) !== null && _h !== void 0 ? _h : 0), ((_k = (_j = this.c) === null || _j === void 0 ? void 0 : _j.id) !== null && _k !== void 0 ? _k : 0), ((_m = (_l = this.c) === null || _l === void 0 ? void 0 : _l.distance) !== null && _m !== void 0 ? _m : 0));
|
||||
}
|
||||
}
|
||||
88
tests/ts/my-game/example/struct-of-structs.ts
Normal file
88
tests/ts/my-game/example/struct-of-structs.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { Ability, AbilityT } from '../../my-game/example/ability.js';
|
||||
import { Test, TestT } from '../../my-game/example/test.js';
|
||||
|
||||
|
||||
export class StructOfStructs {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):StructOfStructs {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
a(obj?:Ability):Ability|null {
|
||||
return (obj || new Ability()).__init(this.bb_pos, this.bb!);
|
||||
}
|
||||
|
||||
b(obj?:Test):Test|null {
|
||||
return (obj || new Test()).__init(this.bb_pos + 8, this.bb!);
|
||||
}
|
||||
|
||||
c(obj?:Ability):Ability|null {
|
||||
return (obj || new Ability()).__init(this.bb_pos + 12, this.bb!);
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'MyGame_Example_StructOfStructs';
|
||||
}
|
||||
|
||||
static sizeOf():number {
|
||||
return 20;
|
||||
}
|
||||
|
||||
static createStructOfStructs(builder:flatbuffers.Builder, a_id: number, a_distance: number, b_a: number, b_b: number, c_id: number, c_distance: number):flatbuffers.Offset {
|
||||
builder.prep(4, 20);
|
||||
builder.prep(4, 8);
|
||||
builder.writeInt32(c_distance);
|
||||
builder.writeInt32(c_id);
|
||||
builder.prep(2, 4);
|
||||
builder.pad(1);
|
||||
builder.writeInt8(b_b);
|
||||
builder.writeInt16(b_a);
|
||||
builder.prep(4, 8);
|
||||
builder.writeInt32(a_distance);
|
||||
builder.writeInt32(a_id);
|
||||
return builder.offset();
|
||||
}
|
||||
|
||||
|
||||
unpack(): StructOfStructsT {
|
||||
return new StructOfStructsT(
|
||||
(this.a() !== null ? this.a()!.unpack() : null),
|
||||
(this.b() !== null ? this.b()!.unpack() : null),
|
||||
(this.c() !== null ? this.c()!.unpack() : null)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: StructOfStructsT): void {
|
||||
_o.a = (this.a() !== null ? this.a()!.unpack() : null);
|
||||
_o.b = (this.b() !== null ? this.b()!.unpack() : null);
|
||||
_o.c = (this.c() !== null ? this.c()!.unpack() : null);
|
||||
}
|
||||
}
|
||||
|
||||
export class StructOfStructsT {
|
||||
constructor(
|
||||
public a: AbilityT|null = null,
|
||||
public b: TestT|null = null,
|
||||
public c: AbilityT|null = null
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return StructOfStructs.createStructOfStructs(builder,
|
||||
(this.a?.id ?? 0),
|
||||
(this.a?.distance ?? 0),
|
||||
(this.b?.a ?? 0),
|
||||
(this.b?.b ?? 0),
|
||||
(this.c?.id ?? 0),
|
||||
(this.c?.distance ?? 0)
|
||||
);
|
||||
}
|
||||
}
|
||||
71
tests/ts/my-game/example/test-simple-table-with-enum.js
Normal file
71
tests/ts/my-game/example/test-simple-table-with-enum.js
Normal file
@@ -0,0 +1,71 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
import { Color } from '../../my-game/example/color.js';
|
||||
export class TestSimpleTableWithEnum {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsTestSimpleTableWithEnum(bb, obj) {
|
||||
return (obj || new TestSimpleTableWithEnum()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsTestSimpleTableWithEnum(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new TestSimpleTableWithEnum()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
color() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.readUint8(this.bb_pos + offset) : Color.Green;
|
||||
}
|
||||
mutate_color(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeUint8(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'MyGame_Example_TestSimpleTableWithEnum';
|
||||
}
|
||||
static startTestSimpleTableWithEnum(builder) {
|
||||
builder.startObject(1);
|
||||
}
|
||||
static addColor(builder, color) {
|
||||
builder.addFieldInt8(0, color, Color.Green);
|
||||
}
|
||||
static endTestSimpleTableWithEnum(builder) {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
static createTestSimpleTableWithEnum(builder, color) {
|
||||
TestSimpleTableWithEnum.startTestSimpleTableWithEnum(builder);
|
||||
TestSimpleTableWithEnum.addColor(builder, color);
|
||||
return TestSimpleTableWithEnum.endTestSimpleTableWithEnum(builder);
|
||||
}
|
||||
serialize() {
|
||||
return this.bb.bytes();
|
||||
}
|
||||
static deserialize(buffer) {
|
||||
return TestSimpleTableWithEnum.getRootAsTestSimpleTableWithEnum(new flatbuffers.ByteBuffer(buffer));
|
||||
}
|
||||
unpack() {
|
||||
return new TestSimpleTableWithEnumT(this.color());
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.color = this.color();
|
||||
}
|
||||
}
|
||||
export class TestSimpleTableWithEnumT {
|
||||
constructor(color = Color.Green) {
|
||||
this.color = color;
|
||||
}
|
||||
pack(builder) {
|
||||
return TestSimpleTableWithEnum.createTestSimpleTableWithEnum(builder, this.color);
|
||||
}
|
||||
}
|
||||
96
tests/ts/my-game/example/test-simple-table-with-enum.ts
Normal file
96
tests/ts/my-game/example/test-simple-table-with-enum.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { Color } from '../../my-game/example/color.js';
|
||||
|
||||
|
||||
export class TestSimpleTableWithEnum {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):TestSimpleTableWithEnum {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsTestSimpleTableWithEnum(bb:flatbuffers.ByteBuffer, obj?:TestSimpleTableWithEnum):TestSimpleTableWithEnum {
|
||||
return (obj || new TestSimpleTableWithEnum()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsTestSimpleTableWithEnum(bb:flatbuffers.ByteBuffer, obj?:TestSimpleTableWithEnum):TestSimpleTableWithEnum {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new TestSimpleTableWithEnum()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
color():Color {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.readUint8(this.bb_pos + offset) : Color.Green;
|
||||
}
|
||||
|
||||
mutate_color(value:Color):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeUint8(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'MyGame_Example_TestSimpleTableWithEnum';
|
||||
}
|
||||
|
||||
static startTestSimpleTableWithEnum(builder:flatbuffers.Builder) {
|
||||
builder.startObject(1);
|
||||
}
|
||||
|
||||
static addColor(builder:flatbuffers.Builder, color:Color) {
|
||||
builder.addFieldInt8(0, color, Color.Green);
|
||||
}
|
||||
|
||||
static endTestSimpleTableWithEnum(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createTestSimpleTableWithEnum(builder:flatbuffers.Builder, color:Color):flatbuffers.Offset {
|
||||
TestSimpleTableWithEnum.startTestSimpleTableWithEnum(builder);
|
||||
TestSimpleTableWithEnum.addColor(builder, color);
|
||||
return TestSimpleTableWithEnum.endTestSimpleTableWithEnum(builder);
|
||||
}
|
||||
|
||||
serialize():Uint8Array {
|
||||
return this.bb!.bytes();
|
||||
}
|
||||
|
||||
static deserialize(buffer: Uint8Array):TestSimpleTableWithEnum {
|
||||
return TestSimpleTableWithEnum.getRootAsTestSimpleTableWithEnum(new flatbuffers.ByteBuffer(buffer))
|
||||
}
|
||||
|
||||
unpack(): TestSimpleTableWithEnumT {
|
||||
return new TestSimpleTableWithEnumT(
|
||||
this.color()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: TestSimpleTableWithEnumT): void {
|
||||
_o.color = this.color();
|
||||
}
|
||||
}
|
||||
|
||||
export class TestSimpleTableWithEnumT {
|
||||
constructor(
|
||||
public color: Color = Color.Green
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return TestSimpleTableWithEnum.createTestSimpleTableWithEnum(builder,
|
||||
this.color
|
||||
);
|
||||
}
|
||||
}
|
||||
55
tests/ts/my-game/example/test.js
Normal file
55
tests/ts/my-game/example/test.js
Normal file
@@ -0,0 +1,55 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
export class Test {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
a() {
|
||||
return this.bb.readInt16(this.bb_pos);
|
||||
}
|
||||
mutate_a(value) {
|
||||
this.bb.writeInt16(this.bb_pos + 0, value);
|
||||
return true;
|
||||
}
|
||||
b() {
|
||||
return this.bb.readInt8(this.bb_pos + 2);
|
||||
}
|
||||
mutate_b(value) {
|
||||
this.bb.writeInt8(this.bb_pos + 2, value);
|
||||
return true;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'MyGame_Example_Test';
|
||||
}
|
||||
static sizeOf() {
|
||||
return 4;
|
||||
}
|
||||
static createTest(builder, a, b) {
|
||||
builder.prep(2, 4);
|
||||
builder.pad(1);
|
||||
builder.writeInt8(b);
|
||||
builder.writeInt16(a);
|
||||
return builder.offset();
|
||||
}
|
||||
unpack() {
|
||||
return new TestT(this.a(), this.b());
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.a = this.a();
|
||||
_o.b = this.b();
|
||||
}
|
||||
}
|
||||
export class TestT {
|
||||
constructor(a = 0, b = 0) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
pack(builder) {
|
||||
return Test.createTest(builder, this.a, this.b);
|
||||
}
|
||||
}
|
||||
78
tests/ts/my-game/example/test.ts
Normal file
78
tests/ts/my-game/example/test.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
export class Test {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Test {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
a():number {
|
||||
return this.bb!.readInt16(this.bb_pos);
|
||||
}
|
||||
|
||||
mutate_a(value:number):boolean {
|
||||
this.bb!.writeInt16(this.bb_pos + 0, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
b():number {
|
||||
return this.bb!.readInt8(this.bb_pos + 2);
|
||||
}
|
||||
|
||||
mutate_b(value:number):boolean {
|
||||
this.bb!.writeInt8(this.bb_pos + 2, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'MyGame_Example_Test';
|
||||
}
|
||||
|
||||
static sizeOf():number {
|
||||
return 4;
|
||||
}
|
||||
|
||||
static createTest(builder:flatbuffers.Builder, a: number, b: number):flatbuffers.Offset {
|
||||
builder.prep(2, 4);
|
||||
builder.pad(1);
|
||||
builder.writeInt8(b);
|
||||
builder.writeInt16(a);
|
||||
return builder.offset();
|
||||
}
|
||||
|
||||
|
||||
unpack(): TestT {
|
||||
return new TestT(
|
||||
this.a(),
|
||||
this.b()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: TestT): void {
|
||||
_o.a = this.a();
|
||||
_o.b = this.b();
|
||||
}
|
||||
}
|
||||
|
||||
export class TestT {
|
||||
constructor(
|
||||
public a: number = 0,
|
||||
public b: number = 0
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return Test.createTest(builder,
|
||||
this.a,
|
||||
this.b
|
||||
);
|
||||
}
|
||||
}
|
||||
290
tests/ts/my-game/example/type-aliases.js
Normal file
290
tests/ts/my-game/example/type-aliases.js
Normal file
@@ -0,0 +1,290 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
export class TypeAliases {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsTypeAliases(bb, obj) {
|
||||
return (obj || new TypeAliases()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsTypeAliases(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new TypeAliases()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
i8() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.readInt8(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_i8(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt8(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
u8() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb.readUint8(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_u8(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeUint8(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
i16() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb.readInt16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_i16(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt16(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
u16() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb.readUint16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_u16(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeUint16(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
i32() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_i32(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
u32() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb.readUint32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_u32(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeUint32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
i64() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 16);
|
||||
return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
mutate_i64(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 16);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
u64() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 18);
|
||||
return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
mutate_u64(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 18);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeUint64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
f32() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 20);
|
||||
return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0.0;
|
||||
}
|
||||
mutate_f32(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 20);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeFloat32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
f64() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 22);
|
||||
return offset ? this.bb.readFloat64(this.bb_pos + offset) : 0.0;
|
||||
}
|
||||
mutate_f64(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 22);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeFloat64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
v8(index) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 24);
|
||||
return offset ? this.bb.readInt8(this.bb.__vector(this.bb_pos + offset) + index) : 0;
|
||||
}
|
||||
v8Length() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 24);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
v8Array() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 24);
|
||||
return offset ? new Int8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
|
||||
}
|
||||
vf64(index) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 26);
|
||||
return offset ? this.bb.readFloat64(this.bb.__vector(this.bb_pos + offset) + index * 8) : 0;
|
||||
}
|
||||
vf64Length() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 26);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
vf64Array() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 26);
|
||||
return offset ? new Float64Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'MyGame_Example_TypeAliases';
|
||||
}
|
||||
static startTypeAliases(builder) {
|
||||
builder.startObject(12);
|
||||
}
|
||||
static addI8(builder, i8) {
|
||||
builder.addFieldInt8(0, i8, 0);
|
||||
}
|
||||
static addU8(builder, u8) {
|
||||
builder.addFieldInt8(1, u8, 0);
|
||||
}
|
||||
static addI16(builder, i16) {
|
||||
builder.addFieldInt16(2, i16, 0);
|
||||
}
|
||||
static addU16(builder, u16) {
|
||||
builder.addFieldInt16(3, u16, 0);
|
||||
}
|
||||
static addI32(builder, i32) {
|
||||
builder.addFieldInt32(4, i32, 0);
|
||||
}
|
||||
static addU32(builder, u32) {
|
||||
builder.addFieldInt32(5, u32, 0);
|
||||
}
|
||||
static addI64(builder, i64) {
|
||||
builder.addFieldInt64(6, i64, BigInt('0'));
|
||||
}
|
||||
static addU64(builder, u64) {
|
||||
builder.addFieldInt64(7, u64, BigInt('0'));
|
||||
}
|
||||
static addF32(builder, f32) {
|
||||
builder.addFieldFloat32(8, f32, 0.0);
|
||||
}
|
||||
static addF64(builder, f64) {
|
||||
builder.addFieldFloat64(9, f64, 0.0);
|
||||
}
|
||||
static addV8(builder, v8Offset) {
|
||||
builder.addFieldOffset(10, v8Offset, 0);
|
||||
}
|
||||
static createV8Vector(builder, data) {
|
||||
builder.startVector(1, data.length, 1);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addInt8(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startV8Vector(builder, numElems) {
|
||||
builder.startVector(1, numElems, 1);
|
||||
}
|
||||
static addVf64(builder, vf64Offset) {
|
||||
builder.addFieldOffset(11, vf64Offset, 0);
|
||||
}
|
||||
static createVf64Vector(builder, data) {
|
||||
builder.startVector(8, data.length, 8);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addFloat64(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startVf64Vector(builder, numElems) {
|
||||
builder.startVector(8, numElems, 8);
|
||||
}
|
||||
static endTypeAliases(builder) {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
static createTypeAliases(builder, i8, u8, i16, u16, i32, u32, i64, u64, f32, f64, v8Offset, vf64Offset) {
|
||||
TypeAliases.startTypeAliases(builder);
|
||||
TypeAliases.addI8(builder, i8);
|
||||
TypeAliases.addU8(builder, u8);
|
||||
TypeAliases.addI16(builder, i16);
|
||||
TypeAliases.addU16(builder, u16);
|
||||
TypeAliases.addI32(builder, i32);
|
||||
TypeAliases.addU32(builder, u32);
|
||||
TypeAliases.addI64(builder, i64);
|
||||
TypeAliases.addU64(builder, u64);
|
||||
TypeAliases.addF32(builder, f32);
|
||||
TypeAliases.addF64(builder, f64);
|
||||
TypeAliases.addV8(builder, v8Offset);
|
||||
TypeAliases.addVf64(builder, vf64Offset);
|
||||
return TypeAliases.endTypeAliases(builder);
|
||||
}
|
||||
serialize() {
|
||||
return this.bb.bytes();
|
||||
}
|
||||
static deserialize(buffer) {
|
||||
return TypeAliases.getRootAsTypeAliases(new flatbuffers.ByteBuffer(buffer));
|
||||
}
|
||||
unpack() {
|
||||
return new TypeAliasesT(this.i8(), this.u8(), this.i16(), this.u16(), this.i32(), this.u32(), this.i64(), this.u64(), this.f32(), this.f64(), this.bb.createScalarList(this.v8.bind(this), this.v8Length()), this.bb.createScalarList(this.vf64.bind(this), this.vf64Length()));
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.i8 = this.i8();
|
||||
_o.u8 = this.u8();
|
||||
_o.i16 = this.i16();
|
||||
_o.u16 = this.u16();
|
||||
_o.i32 = this.i32();
|
||||
_o.u32 = this.u32();
|
||||
_o.i64 = this.i64();
|
||||
_o.u64 = this.u64();
|
||||
_o.f32 = this.f32();
|
||||
_o.f64 = this.f64();
|
||||
_o.v8 = this.bb.createScalarList(this.v8.bind(this), this.v8Length());
|
||||
_o.vf64 = this.bb.createScalarList(this.vf64.bind(this), this.vf64Length());
|
||||
}
|
||||
}
|
||||
export class TypeAliasesT {
|
||||
constructor(i8 = 0, u8 = 0, i16 = 0, u16 = 0, i32 = 0, u32 = 0, i64 = BigInt('0'), u64 = BigInt('0'), f32 = 0.0, f64 = 0.0, v8 = [], vf64 = []) {
|
||||
this.i8 = i8;
|
||||
this.u8 = u8;
|
||||
this.i16 = i16;
|
||||
this.u16 = u16;
|
||||
this.i32 = i32;
|
||||
this.u32 = u32;
|
||||
this.i64 = i64;
|
||||
this.u64 = u64;
|
||||
this.f32 = f32;
|
||||
this.f64 = f64;
|
||||
this.v8 = v8;
|
||||
this.vf64 = vf64;
|
||||
}
|
||||
pack(builder) {
|
||||
const v8 = TypeAliases.createV8Vector(builder, this.v8);
|
||||
const vf64 = TypeAliases.createVf64Vector(builder, this.vf64);
|
||||
return TypeAliases.createTypeAliases(builder, this.i8, this.u8, this.i16, this.u16, this.i32, this.u32, this.i64, this.u64, this.f32, this.f64, v8, vf64);
|
||||
}
|
||||
}
|
||||
405
tests/ts/my-game/example/type-aliases.ts
Normal file
405
tests/ts/my-game/example/type-aliases.ts
Normal file
@@ -0,0 +1,405 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
export class TypeAliases {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):TypeAliases {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsTypeAliases(bb:flatbuffers.ByteBuffer, obj?:TypeAliases):TypeAliases {
|
||||
return (obj || new TypeAliases()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsTypeAliases(bb:flatbuffers.ByteBuffer, obj?:TypeAliases):TypeAliases {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new TypeAliases()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
i8():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.readInt8(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_i8(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt8(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
u8():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.readUint8(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_u8(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeUint8(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
i16():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb!.readInt16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_i16(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt16(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
u16():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_u16(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeUint16(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
i32():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_i32(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
u32():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb!.readUint32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_u32(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeUint32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
i64():bigint {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 16);
|
||||
return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
|
||||
mutate_i64(value:bigint):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 16);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
u64():bigint {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 18);
|
||||
return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
|
||||
mutate_u64(value:bigint):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 18);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeUint64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
f32():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 20);
|
||||
return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 0.0;
|
||||
}
|
||||
|
||||
mutate_f32(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 20);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeFloat32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
f64():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 22);
|
||||
return offset ? this.bb!.readFloat64(this.bb_pos + offset) : 0.0;
|
||||
}
|
||||
|
||||
mutate_f64(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 22);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeFloat64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
v8(index: number):number|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 24);
|
||||
return offset ? this.bb!.readInt8(this.bb!.__vector(this.bb_pos + offset) + index) : 0;
|
||||
}
|
||||
|
||||
v8Length():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 24);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
v8Array():Int8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 24);
|
||||
return offset ? new Int8Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null;
|
||||
}
|
||||
|
||||
vf64(index: number):number|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 26);
|
||||
return offset ? this.bb!.readFloat64(this.bb!.__vector(this.bb_pos + offset) + index * 8) : 0;
|
||||
}
|
||||
|
||||
vf64Length():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 26);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
vf64Array():Float64Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 26);
|
||||
return offset ? new Float64Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'MyGame_Example_TypeAliases';
|
||||
}
|
||||
|
||||
static startTypeAliases(builder:flatbuffers.Builder) {
|
||||
builder.startObject(12);
|
||||
}
|
||||
|
||||
static addI8(builder:flatbuffers.Builder, i8:number) {
|
||||
builder.addFieldInt8(0, i8, 0);
|
||||
}
|
||||
|
||||
static addU8(builder:flatbuffers.Builder, u8:number) {
|
||||
builder.addFieldInt8(1, u8, 0);
|
||||
}
|
||||
|
||||
static addI16(builder:flatbuffers.Builder, i16:number) {
|
||||
builder.addFieldInt16(2, i16, 0);
|
||||
}
|
||||
|
||||
static addU16(builder:flatbuffers.Builder, u16:number) {
|
||||
builder.addFieldInt16(3, u16, 0);
|
||||
}
|
||||
|
||||
static addI32(builder:flatbuffers.Builder, i32:number) {
|
||||
builder.addFieldInt32(4, i32, 0);
|
||||
}
|
||||
|
||||
static addU32(builder:flatbuffers.Builder, u32:number) {
|
||||
builder.addFieldInt32(5, u32, 0);
|
||||
}
|
||||
|
||||
static addI64(builder:flatbuffers.Builder, i64:bigint) {
|
||||
builder.addFieldInt64(6, i64, BigInt('0'));
|
||||
}
|
||||
|
||||
static addU64(builder:flatbuffers.Builder, u64:bigint) {
|
||||
builder.addFieldInt64(7, u64, BigInt('0'));
|
||||
}
|
||||
|
||||
static addF32(builder:flatbuffers.Builder, f32:number) {
|
||||
builder.addFieldFloat32(8, f32, 0.0);
|
||||
}
|
||||
|
||||
static addF64(builder:flatbuffers.Builder, f64:number) {
|
||||
builder.addFieldFloat64(9, f64, 0.0);
|
||||
}
|
||||
|
||||
static addV8(builder:flatbuffers.Builder, v8Offset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(10, v8Offset, 0);
|
||||
}
|
||||
|
||||
static createV8Vector(builder:flatbuffers.Builder, data:number[]|Int8Array):flatbuffers.Offset;
|
||||
/**
|
||||
* @deprecated This Uint8Array overload will be removed in the future.
|
||||
*/
|
||||
static createV8Vector(builder:flatbuffers.Builder, data:number[]|Uint8Array):flatbuffers.Offset;
|
||||
static createV8Vector(builder:flatbuffers.Builder, data:number[]|Int8Array|Uint8Array):flatbuffers.Offset {
|
||||
builder.startVector(1, data.length, 1);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addInt8(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startV8Vector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(1, numElems, 1);
|
||||
}
|
||||
|
||||
static addVf64(builder:flatbuffers.Builder, vf64Offset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(11, vf64Offset, 0);
|
||||
}
|
||||
|
||||
static createVf64Vector(builder:flatbuffers.Builder, data:number[]|Float64Array):flatbuffers.Offset;
|
||||
/**
|
||||
* @deprecated This Uint8Array overload will be removed in the future.
|
||||
*/
|
||||
static createVf64Vector(builder:flatbuffers.Builder, data:number[]|Uint8Array):flatbuffers.Offset;
|
||||
static createVf64Vector(builder:flatbuffers.Builder, data:number[]|Float64Array|Uint8Array):flatbuffers.Offset {
|
||||
builder.startVector(8, data.length, 8);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addFloat64(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startVf64Vector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(8, numElems, 8);
|
||||
}
|
||||
|
||||
static endTypeAliases(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createTypeAliases(builder:flatbuffers.Builder, i8:number, u8:number, i16:number, u16:number, i32:number, u32:number, i64:bigint, u64:bigint, f32:number, f64:number, v8Offset:flatbuffers.Offset, vf64Offset:flatbuffers.Offset):flatbuffers.Offset {
|
||||
TypeAliases.startTypeAliases(builder);
|
||||
TypeAliases.addI8(builder, i8);
|
||||
TypeAliases.addU8(builder, u8);
|
||||
TypeAliases.addI16(builder, i16);
|
||||
TypeAliases.addU16(builder, u16);
|
||||
TypeAliases.addI32(builder, i32);
|
||||
TypeAliases.addU32(builder, u32);
|
||||
TypeAliases.addI64(builder, i64);
|
||||
TypeAliases.addU64(builder, u64);
|
||||
TypeAliases.addF32(builder, f32);
|
||||
TypeAliases.addF64(builder, f64);
|
||||
TypeAliases.addV8(builder, v8Offset);
|
||||
TypeAliases.addVf64(builder, vf64Offset);
|
||||
return TypeAliases.endTypeAliases(builder);
|
||||
}
|
||||
|
||||
serialize():Uint8Array {
|
||||
return this.bb!.bytes();
|
||||
}
|
||||
|
||||
static deserialize(buffer: Uint8Array):TypeAliases {
|
||||
return TypeAliases.getRootAsTypeAliases(new flatbuffers.ByteBuffer(buffer))
|
||||
}
|
||||
|
||||
unpack(): TypeAliasesT {
|
||||
return new TypeAliasesT(
|
||||
this.i8(),
|
||||
this.u8(),
|
||||
this.i16(),
|
||||
this.u16(),
|
||||
this.i32(),
|
||||
this.u32(),
|
||||
this.i64(),
|
||||
this.u64(),
|
||||
this.f32(),
|
||||
this.f64(),
|
||||
this.bb!.createScalarList(this.v8.bind(this), this.v8Length()),
|
||||
this.bb!.createScalarList(this.vf64.bind(this), this.vf64Length())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: TypeAliasesT): void {
|
||||
_o.i8 = this.i8();
|
||||
_o.u8 = this.u8();
|
||||
_o.i16 = this.i16();
|
||||
_o.u16 = this.u16();
|
||||
_o.i32 = this.i32();
|
||||
_o.u32 = this.u32();
|
||||
_o.i64 = this.i64();
|
||||
_o.u64 = this.u64();
|
||||
_o.f32 = this.f32();
|
||||
_o.f64 = this.f64();
|
||||
_o.v8 = this.bb!.createScalarList(this.v8.bind(this), this.v8Length());
|
||||
_o.vf64 = this.bb!.createScalarList(this.vf64.bind(this), this.vf64Length());
|
||||
}
|
||||
}
|
||||
|
||||
export class TypeAliasesT {
|
||||
constructor(
|
||||
public i8: number = 0,
|
||||
public u8: number = 0,
|
||||
public i16: number = 0,
|
||||
public u16: number = 0,
|
||||
public i32: number = 0,
|
||||
public u32: number = 0,
|
||||
public i64: bigint = BigInt('0'),
|
||||
public u64: bigint = BigInt('0'),
|
||||
public f32: number = 0.0,
|
||||
public f64: number = 0.0,
|
||||
public v8: (number)[] = [],
|
||||
public vf64: (number)[] = []
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const v8 = TypeAliases.createV8Vector(builder, this.v8);
|
||||
const vf64 = TypeAliases.createVf64Vector(builder, this.vf64);
|
||||
|
||||
return TypeAliases.createTypeAliases(builder,
|
||||
this.i8,
|
||||
this.u8,
|
||||
this.i16,
|
||||
this.u16,
|
||||
this.i32,
|
||||
this.u32,
|
||||
this.i64,
|
||||
this.u64,
|
||||
this.f32,
|
||||
this.f64,
|
||||
v8,
|
||||
vf64
|
||||
);
|
||||
}
|
||||
}
|
||||
98
tests/ts/my-game/example/vec3.js
Normal file
98
tests/ts/my-game/example/vec3.js
Normal file
@@ -0,0 +1,98 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import { Test } from '../../my-game/example/test.js';
|
||||
export class Vec3 {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
x() {
|
||||
return this.bb.readFloat32(this.bb_pos);
|
||||
}
|
||||
mutate_x(value) {
|
||||
this.bb.writeFloat32(this.bb_pos + 0, value);
|
||||
return true;
|
||||
}
|
||||
y() {
|
||||
return this.bb.readFloat32(this.bb_pos + 4);
|
||||
}
|
||||
mutate_y(value) {
|
||||
this.bb.writeFloat32(this.bb_pos + 4, value);
|
||||
return true;
|
||||
}
|
||||
z() {
|
||||
return this.bb.readFloat32(this.bb_pos + 8);
|
||||
}
|
||||
mutate_z(value) {
|
||||
this.bb.writeFloat32(this.bb_pos + 8, value);
|
||||
return true;
|
||||
}
|
||||
test1() {
|
||||
return this.bb.readFloat64(this.bb_pos + 16);
|
||||
}
|
||||
mutate_test1(value) {
|
||||
this.bb.writeFloat64(this.bb_pos + 16, value);
|
||||
return true;
|
||||
}
|
||||
test2() {
|
||||
return this.bb.readUint8(this.bb_pos + 24);
|
||||
}
|
||||
mutate_test2(value) {
|
||||
this.bb.writeUint8(this.bb_pos + 24, value);
|
||||
return true;
|
||||
}
|
||||
test3(obj) {
|
||||
return (obj || new Test()).__init(this.bb_pos + 26, this.bb);
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'MyGame_Example_Vec3';
|
||||
}
|
||||
static sizeOf() {
|
||||
return 32;
|
||||
}
|
||||
static createVec3(builder, x, y, z, test1, test2, test3_a, test3_b) {
|
||||
builder.prep(8, 32);
|
||||
builder.pad(2);
|
||||
builder.prep(2, 4);
|
||||
builder.pad(1);
|
||||
builder.writeInt8(test3_b);
|
||||
builder.writeInt16(test3_a);
|
||||
builder.pad(1);
|
||||
builder.writeInt8(test2);
|
||||
builder.writeFloat64(test1);
|
||||
builder.pad(4);
|
||||
builder.writeFloat32(z);
|
||||
builder.writeFloat32(y);
|
||||
builder.writeFloat32(x);
|
||||
return builder.offset();
|
||||
}
|
||||
unpack() {
|
||||
return new Vec3T(this.x(), this.y(), this.z(), this.test1(), this.test2(), (this.test3() !== null ? this.test3().unpack() : null));
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.x = this.x();
|
||||
_o.y = this.y();
|
||||
_o.z = this.z();
|
||||
_o.test1 = this.test1();
|
||||
_o.test2 = this.test2();
|
||||
_o.test3 = (this.test3() !== null ? this.test3().unpack() : null);
|
||||
}
|
||||
}
|
||||
export class Vec3T {
|
||||
constructor(x = 0.0, y = 0.0, z = 0.0, test1 = 0.0, test2 = 0, test3 = null) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.test1 = test1;
|
||||
this.test2 = test2;
|
||||
this.test3 = test3;
|
||||
}
|
||||
pack(builder) {
|
||||
var _a, _b, _c, _d;
|
||||
return Vec3.createVec3(builder, this.x, this.y, this.z, this.test1, this.test2, ((_b = (_a = this.test3) === null || _a === void 0 ? void 0 : _a.a) !== null && _b !== void 0 ? _b : 0), ((_d = (_c = this.test3) === null || _c === void 0 ? void 0 : _c.b) !== null && _d !== void 0 ? _d : 0));
|
||||
}
|
||||
}
|
||||
137
tests/ts/my-game/example/vec3.ts
Normal file
137
tests/ts/my-game/example/vec3.ts
Normal file
@@ -0,0 +1,137 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { Color } from '../../my-game/example/color.js';
|
||||
import { Test, TestT } from '../../my-game/example/test.js';
|
||||
|
||||
|
||||
export class Vec3 {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Vec3 {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
x():number {
|
||||
return this.bb!.readFloat32(this.bb_pos);
|
||||
}
|
||||
|
||||
mutate_x(value:number):boolean {
|
||||
this.bb!.writeFloat32(this.bb_pos + 0, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
y():number {
|
||||
return this.bb!.readFloat32(this.bb_pos + 4);
|
||||
}
|
||||
|
||||
mutate_y(value:number):boolean {
|
||||
this.bb!.writeFloat32(this.bb_pos + 4, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
z():number {
|
||||
return this.bb!.readFloat32(this.bb_pos + 8);
|
||||
}
|
||||
|
||||
mutate_z(value:number):boolean {
|
||||
this.bb!.writeFloat32(this.bb_pos + 8, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
test1():number {
|
||||
return this.bb!.readFloat64(this.bb_pos + 16);
|
||||
}
|
||||
|
||||
mutate_test1(value:number):boolean {
|
||||
this.bb!.writeFloat64(this.bb_pos + 16, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
test2():Color {
|
||||
return this.bb!.readUint8(this.bb_pos + 24);
|
||||
}
|
||||
|
||||
mutate_test2(value:Color):boolean {
|
||||
this.bb!.writeUint8(this.bb_pos + 24, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
test3(obj?:Test):Test|null {
|
||||
return (obj || new Test()).__init(this.bb_pos + 26, this.bb!);
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'MyGame_Example_Vec3';
|
||||
}
|
||||
|
||||
static sizeOf():number {
|
||||
return 32;
|
||||
}
|
||||
|
||||
static createVec3(builder:flatbuffers.Builder, x: number, y: number, z: number, test1: number, test2: Color, test3_a: number, test3_b: number):flatbuffers.Offset {
|
||||
builder.prep(8, 32);
|
||||
builder.pad(2);
|
||||
builder.prep(2, 4);
|
||||
builder.pad(1);
|
||||
builder.writeInt8(test3_b);
|
||||
builder.writeInt16(test3_a);
|
||||
builder.pad(1);
|
||||
builder.writeInt8(test2);
|
||||
builder.writeFloat64(test1);
|
||||
builder.pad(4);
|
||||
builder.writeFloat32(z);
|
||||
builder.writeFloat32(y);
|
||||
builder.writeFloat32(x);
|
||||
return builder.offset();
|
||||
}
|
||||
|
||||
|
||||
unpack(): Vec3T {
|
||||
return new Vec3T(
|
||||
this.x(),
|
||||
this.y(),
|
||||
this.z(),
|
||||
this.test1(),
|
||||
this.test2(),
|
||||
(this.test3() !== null ? this.test3()!.unpack() : null)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: Vec3T): void {
|
||||
_o.x = this.x();
|
||||
_o.y = this.y();
|
||||
_o.z = this.z();
|
||||
_o.test1 = this.test1();
|
||||
_o.test2 = this.test2();
|
||||
_o.test3 = (this.test3() !== null ? this.test3()!.unpack() : null);
|
||||
}
|
||||
}
|
||||
|
||||
export class Vec3T {
|
||||
constructor(
|
||||
public x: number = 0.0,
|
||||
public y: number = 0.0,
|
||||
public z: number = 0.0,
|
||||
public test1: number = 0.0,
|
||||
public test2: Color = 0,
|
||||
public test3: TestT|null = null
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return Vec3.createVec3(builder,
|
||||
this.x,
|
||||
this.y,
|
||||
this.z,
|
||||
this.test1,
|
||||
this.test2,
|
||||
(this.test3?.a ?? 0),
|
||||
(this.test3?.b ?? 0)
|
||||
);
|
||||
}
|
||||
}
|
||||
50
tests/ts/my-game/example2/monster.js
Normal file
50
tests/ts/my-game/example2/monster.js
Normal file
@@ -0,0 +1,50 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
export class Monster {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsMonster(bb, obj) {
|
||||
return (obj || new Monster()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsMonster(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Monster()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'MyGame_Example2_Monster';
|
||||
}
|
||||
static startMonster(builder) {
|
||||
builder.startObject(0);
|
||||
}
|
||||
static endMonster(builder) {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
static createMonster(builder) {
|
||||
Monster.startMonster(builder);
|
||||
return Monster.endMonster(builder);
|
||||
}
|
||||
serialize() {
|
||||
return this.bb.bytes();
|
||||
}
|
||||
static deserialize(buffer) {
|
||||
return Monster.getRootAsMonster(new flatbuffers.ByteBuffer(buffer));
|
||||
}
|
||||
unpack() {
|
||||
return new MonsterT();
|
||||
}
|
||||
unpackTo(_o) { }
|
||||
}
|
||||
export class MonsterT {
|
||||
constructor() { }
|
||||
pack(builder) {
|
||||
return Monster.createMonster(builder);
|
||||
}
|
||||
}
|
||||
66
tests/ts/my-game/example2/monster.ts
Normal file
66
tests/ts/my-game/example2/monster.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
export class Monster {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Monster {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsMonster(bb:flatbuffers.ByteBuffer, obj?:Monster):Monster {
|
||||
return (obj || new Monster()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsMonster(bb:flatbuffers.ByteBuffer, obj?:Monster):Monster {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Monster()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'MyGame_Example2_Monster';
|
||||
}
|
||||
|
||||
static startMonster(builder:flatbuffers.Builder) {
|
||||
builder.startObject(0);
|
||||
}
|
||||
|
||||
static endMonster(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createMonster(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
Monster.startMonster(builder);
|
||||
return Monster.endMonster(builder);
|
||||
}
|
||||
|
||||
serialize():Uint8Array {
|
||||
return this.bb!.bytes();
|
||||
}
|
||||
|
||||
static deserialize(buffer: Uint8Array):Monster {
|
||||
return Monster.getRootAsMonster(new flatbuffers.ByteBuffer(buffer))
|
||||
}
|
||||
|
||||
unpack(): MonsterT {
|
||||
return new MonsterT();
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: MonsterT): void {}
|
||||
}
|
||||
|
||||
export class MonsterT {
|
||||
constructor(){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return Monster.createMonster(builder);
|
||||
}
|
||||
}
|
||||
50
tests/ts/my-game/in-parent-namespace.js
Normal file
50
tests/ts/my-game/in-parent-namespace.js
Normal file
@@ -0,0 +1,50 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
export class InParentNamespace {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsInParentNamespace(bb, obj) {
|
||||
return (obj || new InParentNamespace()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsInParentNamespace(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new InParentNamespace()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'MyGame_InParentNamespace';
|
||||
}
|
||||
static startInParentNamespace(builder) {
|
||||
builder.startObject(0);
|
||||
}
|
||||
static endInParentNamespace(builder) {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
static createInParentNamespace(builder) {
|
||||
InParentNamespace.startInParentNamespace(builder);
|
||||
return InParentNamespace.endInParentNamespace(builder);
|
||||
}
|
||||
serialize() {
|
||||
return this.bb.bytes();
|
||||
}
|
||||
static deserialize(buffer) {
|
||||
return InParentNamespace.getRootAsInParentNamespace(new flatbuffers.ByteBuffer(buffer));
|
||||
}
|
||||
unpack() {
|
||||
return new InParentNamespaceT();
|
||||
}
|
||||
unpackTo(_o) { }
|
||||
}
|
||||
export class InParentNamespaceT {
|
||||
constructor() { }
|
||||
pack(builder) {
|
||||
return InParentNamespace.createInParentNamespace(builder);
|
||||
}
|
||||
}
|
||||
66
tests/ts/my-game/in-parent-namespace.ts
Normal file
66
tests/ts/my-game/in-parent-namespace.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
export class InParentNamespace {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):InParentNamespace {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsInParentNamespace(bb:flatbuffers.ByteBuffer, obj?:InParentNamespace):InParentNamespace {
|
||||
return (obj || new InParentNamespace()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsInParentNamespace(bb:flatbuffers.ByteBuffer, obj?:InParentNamespace):InParentNamespace {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new InParentNamespace()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'MyGame_InParentNamespace';
|
||||
}
|
||||
|
||||
static startInParentNamespace(builder:flatbuffers.Builder) {
|
||||
builder.startObject(0);
|
||||
}
|
||||
|
||||
static endInParentNamespace(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createInParentNamespace(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
InParentNamespace.startInParentNamespace(builder);
|
||||
return InParentNamespace.endInParentNamespace(builder);
|
||||
}
|
||||
|
||||
serialize():Uint8Array {
|
||||
return this.bb!.bytes();
|
||||
}
|
||||
|
||||
static deserialize(buffer: Uint8Array):InParentNamespace {
|
||||
return InParentNamespace.getRootAsInParentNamespace(new flatbuffers.ByteBuffer(buffer))
|
||||
}
|
||||
|
||||
unpack(): InParentNamespaceT {
|
||||
return new InParentNamespaceT();
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: InParentNamespaceT): void {}
|
||||
}
|
||||
|
||||
export class InParentNamespaceT {
|
||||
constructor(){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return InParentNamespace.createInParentNamespace(builder);
|
||||
}
|
||||
}
|
||||
7
tests/ts/optional-scalars/optional-byte.ts
Normal file
7
tests/ts/optional-scalars/optional-byte.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export enum OptionalByte {
|
||||
None = 0,
|
||||
One = 1,
|
||||
Two = 2
|
||||
}
|
||||
427
tests/ts/optional-scalars/scalar-stuff.ts
Normal file
427
tests/ts/optional-scalars/scalar-stuff.ts
Normal file
@@ -0,0 +1,427 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { OptionalByte } from '../optional-scalars/optional-byte.js';
|
||||
|
||||
|
||||
export class ScalarStuff {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):ScalarStuff {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsScalarStuff(bb:flatbuffers.ByteBuffer, obj?:ScalarStuff):ScalarStuff {
|
||||
return (obj || new ScalarStuff()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsScalarStuff(bb:flatbuffers.ByteBuffer, obj?:ScalarStuff):ScalarStuff {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new ScalarStuff()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static bufferHasIdentifier(bb:flatbuffers.ByteBuffer):boolean {
|
||||
return bb.__has_identifier('NULL');
|
||||
}
|
||||
|
||||
justI8():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.readInt8(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
maybeI8():number|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.readInt8(this.bb_pos + offset) : null;
|
||||
}
|
||||
|
||||
defaultI8():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb!.readInt8(this.bb_pos + offset) : 42;
|
||||
}
|
||||
|
||||
justU8():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb!.readUint8(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
maybeU8():number|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb!.readUint8(this.bb_pos + offset) : null;
|
||||
}
|
||||
|
||||
defaultU8():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb!.readUint8(this.bb_pos + offset) : 42;
|
||||
}
|
||||
|
||||
justI16():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 16);
|
||||
return offset ? this.bb!.readInt16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
maybeI16():number|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 18);
|
||||
return offset ? this.bb!.readInt16(this.bb_pos + offset) : null;
|
||||
}
|
||||
|
||||
defaultI16():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 20);
|
||||
return offset ? this.bb!.readInt16(this.bb_pos + offset) : 42;
|
||||
}
|
||||
|
||||
justU16():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 22);
|
||||
return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
maybeU16():number|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 24);
|
||||
return offset ? this.bb!.readUint16(this.bb_pos + offset) : null;
|
||||
}
|
||||
|
||||
defaultU16():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 26);
|
||||
return offset ? this.bb!.readUint16(this.bb_pos + offset) : 42;
|
||||
}
|
||||
|
||||
justI32():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 28);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
maybeI32():number|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 30);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : null;
|
||||
}
|
||||
|
||||
defaultI32():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 32);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 42;
|
||||
}
|
||||
|
||||
justU32():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 34);
|
||||
return offset ? this.bb!.readUint32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
maybeU32():number|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 36);
|
||||
return offset ? this.bb!.readUint32(this.bb_pos + offset) : null;
|
||||
}
|
||||
|
||||
defaultU32():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 38);
|
||||
return offset ? this.bb!.readUint32(this.bb_pos + offset) : 42;
|
||||
}
|
||||
|
||||
justI64():bigint {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 40);
|
||||
return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
|
||||
maybeI64():bigint|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 42);
|
||||
return offset ? this.bb!.readInt64(this.bb_pos + offset) : null;
|
||||
}
|
||||
|
||||
defaultI64():bigint {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 44);
|
||||
return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('42');
|
||||
}
|
||||
|
||||
justU64():bigint {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 46);
|
||||
return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
|
||||
maybeU64():bigint|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 48);
|
||||
return offset ? this.bb!.readUint64(this.bb_pos + offset) : null;
|
||||
}
|
||||
|
||||
defaultU64():bigint {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 50);
|
||||
return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('42');
|
||||
}
|
||||
|
||||
justF32():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 52);
|
||||
return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 0.0;
|
||||
}
|
||||
|
||||
maybeF32():number|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 54);
|
||||
return offset ? this.bb!.readFloat32(this.bb_pos + offset) : null;
|
||||
}
|
||||
|
||||
defaultF32():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 56);
|
||||
return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 42.0;
|
||||
}
|
||||
|
||||
justF64():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 58);
|
||||
return offset ? this.bb!.readFloat64(this.bb_pos + offset) : 0.0;
|
||||
}
|
||||
|
||||
maybeF64():number|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 60);
|
||||
return offset ? this.bb!.readFloat64(this.bb_pos + offset) : null;
|
||||
}
|
||||
|
||||
defaultF64():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 62);
|
||||
return offset ? this.bb!.readFloat64(this.bb_pos + offset) : 42.0;
|
||||
}
|
||||
|
||||
justBool():boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 64);
|
||||
return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false;
|
||||
}
|
||||
|
||||
maybeBool():boolean|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 66);
|
||||
return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : null;
|
||||
}
|
||||
|
||||
defaultBool():boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 68);
|
||||
return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : true;
|
||||
}
|
||||
|
||||
justEnum():OptionalByte {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 70);
|
||||
return offset ? this.bb!.readInt8(this.bb_pos + offset) : OptionalByte.None;
|
||||
}
|
||||
|
||||
maybeEnum():OptionalByte|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 72);
|
||||
return offset ? this.bb!.readInt8(this.bb_pos + offset) : null;
|
||||
}
|
||||
|
||||
defaultEnum():OptionalByte {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 74);
|
||||
return offset ? this.bb!.readInt8(this.bb_pos + offset) : OptionalByte.One;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'optional_scalars_ScalarStuff';
|
||||
}
|
||||
|
||||
static startScalarStuff(builder:flatbuffers.Builder) {
|
||||
builder.startObject(36);
|
||||
}
|
||||
|
||||
static addJustI8(builder:flatbuffers.Builder, justI8:number) {
|
||||
builder.addFieldInt8(0, justI8, 0);
|
||||
}
|
||||
|
||||
static addMaybeI8(builder:flatbuffers.Builder, maybeI8:number) {
|
||||
builder.addFieldInt8(1, maybeI8, 0);
|
||||
}
|
||||
|
||||
static addDefaultI8(builder:flatbuffers.Builder, defaultI8:number) {
|
||||
builder.addFieldInt8(2, defaultI8, 42);
|
||||
}
|
||||
|
||||
static addJustU8(builder:flatbuffers.Builder, justU8:number) {
|
||||
builder.addFieldInt8(3, justU8, 0);
|
||||
}
|
||||
|
||||
static addMaybeU8(builder:flatbuffers.Builder, maybeU8:number) {
|
||||
builder.addFieldInt8(4, maybeU8, 0);
|
||||
}
|
||||
|
||||
static addDefaultU8(builder:flatbuffers.Builder, defaultU8:number) {
|
||||
builder.addFieldInt8(5, defaultU8, 42);
|
||||
}
|
||||
|
||||
static addJustI16(builder:flatbuffers.Builder, justI16:number) {
|
||||
builder.addFieldInt16(6, justI16, 0);
|
||||
}
|
||||
|
||||
static addMaybeI16(builder:flatbuffers.Builder, maybeI16:number) {
|
||||
builder.addFieldInt16(7, maybeI16, 0);
|
||||
}
|
||||
|
||||
static addDefaultI16(builder:flatbuffers.Builder, defaultI16:number) {
|
||||
builder.addFieldInt16(8, defaultI16, 42);
|
||||
}
|
||||
|
||||
static addJustU16(builder:flatbuffers.Builder, justU16:number) {
|
||||
builder.addFieldInt16(9, justU16, 0);
|
||||
}
|
||||
|
||||
static addMaybeU16(builder:flatbuffers.Builder, maybeU16:number) {
|
||||
builder.addFieldInt16(10, maybeU16, 0);
|
||||
}
|
||||
|
||||
static addDefaultU16(builder:flatbuffers.Builder, defaultU16:number) {
|
||||
builder.addFieldInt16(11, defaultU16, 42);
|
||||
}
|
||||
|
||||
static addJustI32(builder:flatbuffers.Builder, justI32:number) {
|
||||
builder.addFieldInt32(12, justI32, 0);
|
||||
}
|
||||
|
||||
static addMaybeI32(builder:flatbuffers.Builder, maybeI32:number) {
|
||||
builder.addFieldInt32(13, maybeI32, 0);
|
||||
}
|
||||
|
||||
static addDefaultI32(builder:flatbuffers.Builder, defaultI32:number) {
|
||||
builder.addFieldInt32(14, defaultI32, 42);
|
||||
}
|
||||
|
||||
static addJustU32(builder:flatbuffers.Builder, justU32:number) {
|
||||
builder.addFieldInt32(15, justU32, 0);
|
||||
}
|
||||
|
||||
static addMaybeU32(builder:flatbuffers.Builder, maybeU32:number) {
|
||||
builder.addFieldInt32(16, maybeU32, 0);
|
||||
}
|
||||
|
||||
static addDefaultU32(builder:flatbuffers.Builder, defaultU32:number) {
|
||||
builder.addFieldInt32(17, defaultU32, 42);
|
||||
}
|
||||
|
||||
static addJustI64(builder:flatbuffers.Builder, justI64:bigint) {
|
||||
builder.addFieldInt64(18, justI64, BigInt('0'));
|
||||
}
|
||||
|
||||
static addMaybeI64(builder:flatbuffers.Builder, maybeI64:bigint) {
|
||||
builder.addFieldInt64(19, maybeI64, BigInt(0));
|
||||
}
|
||||
|
||||
static addDefaultI64(builder:flatbuffers.Builder, defaultI64:bigint) {
|
||||
builder.addFieldInt64(20, defaultI64, BigInt('42'));
|
||||
}
|
||||
|
||||
static addJustU64(builder:flatbuffers.Builder, justU64:bigint) {
|
||||
builder.addFieldInt64(21, justU64, BigInt('0'));
|
||||
}
|
||||
|
||||
static addMaybeU64(builder:flatbuffers.Builder, maybeU64:bigint) {
|
||||
builder.addFieldInt64(22, maybeU64, BigInt(0));
|
||||
}
|
||||
|
||||
static addDefaultU64(builder:flatbuffers.Builder, defaultU64:bigint) {
|
||||
builder.addFieldInt64(23, defaultU64, BigInt('42'));
|
||||
}
|
||||
|
||||
static addJustF32(builder:flatbuffers.Builder, justF32:number) {
|
||||
builder.addFieldFloat32(24, justF32, 0.0);
|
||||
}
|
||||
|
||||
static addMaybeF32(builder:flatbuffers.Builder, maybeF32:number) {
|
||||
builder.addFieldFloat32(25, maybeF32, 0);
|
||||
}
|
||||
|
||||
static addDefaultF32(builder:flatbuffers.Builder, defaultF32:number) {
|
||||
builder.addFieldFloat32(26, defaultF32, 42.0);
|
||||
}
|
||||
|
||||
static addJustF64(builder:flatbuffers.Builder, justF64:number) {
|
||||
builder.addFieldFloat64(27, justF64, 0.0);
|
||||
}
|
||||
|
||||
static addMaybeF64(builder:flatbuffers.Builder, maybeF64:number) {
|
||||
builder.addFieldFloat64(28, maybeF64, 0);
|
||||
}
|
||||
|
||||
static addDefaultF64(builder:flatbuffers.Builder, defaultF64:number) {
|
||||
builder.addFieldFloat64(29, defaultF64, 42.0);
|
||||
}
|
||||
|
||||
static addJustBool(builder:flatbuffers.Builder, justBool:boolean) {
|
||||
builder.addFieldInt8(30, +justBool, +false);
|
||||
}
|
||||
|
||||
static addMaybeBool(builder:flatbuffers.Builder, maybeBool:boolean) {
|
||||
builder.addFieldInt8(31, +maybeBool, 0);
|
||||
}
|
||||
|
||||
static addDefaultBool(builder:flatbuffers.Builder, defaultBool:boolean) {
|
||||
builder.addFieldInt8(32, +defaultBool, +true);
|
||||
}
|
||||
|
||||
static addJustEnum(builder:flatbuffers.Builder, justEnum:OptionalByte) {
|
||||
builder.addFieldInt8(33, justEnum, OptionalByte.None);
|
||||
}
|
||||
|
||||
static addMaybeEnum(builder:flatbuffers.Builder, maybeEnum:OptionalByte) {
|
||||
builder.addFieldInt8(34, maybeEnum, 0);
|
||||
}
|
||||
|
||||
static addDefaultEnum(builder:flatbuffers.Builder, defaultEnum:OptionalByte) {
|
||||
builder.addFieldInt8(35, defaultEnum, OptionalByte.One);
|
||||
}
|
||||
|
||||
static endScalarStuff(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static finishScalarStuffBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) {
|
||||
builder.finish(offset, 'NULL');
|
||||
}
|
||||
|
||||
static finishSizePrefixedScalarStuffBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) {
|
||||
builder.finish(offset, 'NULL', true);
|
||||
}
|
||||
|
||||
static createScalarStuff(builder:flatbuffers.Builder, justI8:number, maybeI8:number|null, defaultI8:number, justU8:number, maybeU8:number|null, defaultU8:number, justI16:number, maybeI16:number|null, defaultI16:number, justU16:number, maybeU16:number|null, defaultU16:number, justI32:number, maybeI32:number|null, defaultI32:number, justU32:number, maybeU32:number|null, defaultU32:number, justI64:bigint, maybeI64:bigint|null, defaultI64:bigint, justU64:bigint, maybeU64:bigint|null, defaultU64:bigint, justF32:number, maybeF32:number|null, defaultF32:number, justF64:number, maybeF64:number|null, defaultF64:number, justBool:boolean, maybeBool:boolean|null, defaultBool:boolean, justEnum:OptionalByte, maybeEnum:OptionalByte|null, defaultEnum:OptionalByte):flatbuffers.Offset {
|
||||
ScalarStuff.startScalarStuff(builder);
|
||||
ScalarStuff.addJustI8(builder, justI8);
|
||||
if (maybeI8 !== null)
|
||||
ScalarStuff.addMaybeI8(builder, maybeI8);
|
||||
ScalarStuff.addDefaultI8(builder, defaultI8);
|
||||
ScalarStuff.addJustU8(builder, justU8);
|
||||
if (maybeU8 !== null)
|
||||
ScalarStuff.addMaybeU8(builder, maybeU8);
|
||||
ScalarStuff.addDefaultU8(builder, defaultU8);
|
||||
ScalarStuff.addJustI16(builder, justI16);
|
||||
if (maybeI16 !== null)
|
||||
ScalarStuff.addMaybeI16(builder, maybeI16);
|
||||
ScalarStuff.addDefaultI16(builder, defaultI16);
|
||||
ScalarStuff.addJustU16(builder, justU16);
|
||||
if (maybeU16 !== null)
|
||||
ScalarStuff.addMaybeU16(builder, maybeU16);
|
||||
ScalarStuff.addDefaultU16(builder, defaultU16);
|
||||
ScalarStuff.addJustI32(builder, justI32);
|
||||
if (maybeI32 !== null)
|
||||
ScalarStuff.addMaybeI32(builder, maybeI32);
|
||||
ScalarStuff.addDefaultI32(builder, defaultI32);
|
||||
ScalarStuff.addJustU32(builder, justU32);
|
||||
if (maybeU32 !== null)
|
||||
ScalarStuff.addMaybeU32(builder, maybeU32);
|
||||
ScalarStuff.addDefaultU32(builder, defaultU32);
|
||||
ScalarStuff.addJustI64(builder, justI64);
|
||||
if (maybeI64 !== null)
|
||||
ScalarStuff.addMaybeI64(builder, maybeI64);
|
||||
ScalarStuff.addDefaultI64(builder, defaultI64);
|
||||
ScalarStuff.addJustU64(builder, justU64);
|
||||
if (maybeU64 !== null)
|
||||
ScalarStuff.addMaybeU64(builder, maybeU64);
|
||||
ScalarStuff.addDefaultU64(builder, defaultU64);
|
||||
ScalarStuff.addJustF32(builder, justF32);
|
||||
if (maybeF32 !== null)
|
||||
ScalarStuff.addMaybeF32(builder, maybeF32);
|
||||
ScalarStuff.addDefaultF32(builder, defaultF32);
|
||||
ScalarStuff.addJustF64(builder, justF64);
|
||||
if (maybeF64 !== null)
|
||||
ScalarStuff.addMaybeF64(builder, maybeF64);
|
||||
ScalarStuff.addDefaultF64(builder, defaultF64);
|
||||
ScalarStuff.addJustBool(builder, justBool);
|
||||
if (maybeBool !== null)
|
||||
ScalarStuff.addMaybeBool(builder, maybeBool);
|
||||
ScalarStuff.addDefaultBool(builder, defaultBool);
|
||||
ScalarStuff.addJustEnum(builder, justEnum);
|
||||
if (maybeEnum !== null)
|
||||
ScalarStuff.addMaybeEnum(builder, maybeEnum);
|
||||
ScalarStuff.addDefaultEnum(builder, defaultEnum);
|
||||
return ScalarStuff.endScalarStuff(builder);
|
||||
}
|
||||
}
|
||||
1
tests/ts/optional_scalars.ts
Normal file
1
tests/ts/optional_scalars.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { OptionalByte } from './optional-scalars/optional-byte';
|
||||
4
tests/ts/optional_scalars_generated.ts
Normal file
4
tests/ts/optional_scalars_generated.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export { OptionalByte } from './optional-scalars/optional-byte.js';
|
||||
export { ScalarStuff } from './optional-scalars/scalar-stuff.js';
|
||||
7
tests/ts/package.json
Normal file
7
tests/ts/package.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@grpc/grpc-js": "^1.7.0",
|
||||
"flatbuffers": "../../"
|
||||
}
|
||||
}
|
||||
11
tests/ts/reflection/advanced-features.ts
Normal file
11
tests/ts/reflection/advanced-features.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/**
|
||||
* New schema language features that are not supported by old code generators.
|
||||
*/
|
||||
export enum AdvancedFeatures {
|
||||
AdvancedArrayFeatures = '1',
|
||||
AdvancedUnionFeatures = '2',
|
||||
OptionalScalars = '4',
|
||||
DefaultVectorsAndStrings = '8'
|
||||
}
|
||||
23
tests/ts/reflection/base-type.js
Normal file
23
tests/ts/reflection/base-type.js
Normal file
@@ -0,0 +1,23 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
export var BaseType;
|
||||
(function (BaseType) {
|
||||
BaseType[BaseType["None"] = 0] = "None";
|
||||
BaseType[BaseType["UType"] = 1] = "UType";
|
||||
BaseType[BaseType["Bool"] = 2] = "Bool";
|
||||
BaseType[BaseType["Byte"] = 3] = "Byte";
|
||||
BaseType[BaseType["UByte"] = 4] = "UByte";
|
||||
BaseType[BaseType["Short"] = 5] = "Short";
|
||||
BaseType[BaseType["UShort"] = 6] = "UShort";
|
||||
BaseType[BaseType["Int"] = 7] = "Int";
|
||||
BaseType[BaseType["UInt"] = 8] = "UInt";
|
||||
BaseType[BaseType["Long"] = 9] = "Long";
|
||||
BaseType[BaseType["ULong"] = 10] = "ULong";
|
||||
BaseType[BaseType["Float"] = 11] = "Float";
|
||||
BaseType[BaseType["Double"] = 12] = "Double";
|
||||
BaseType[BaseType["String"] = 13] = "String";
|
||||
BaseType[BaseType["Vector"] = 14] = "Vector";
|
||||
BaseType[BaseType["Obj"] = 15] = "Obj";
|
||||
BaseType[BaseType["Union"] = 16] = "Union";
|
||||
BaseType[BaseType["Array"] = 17] = "Array";
|
||||
BaseType[BaseType["MaxBaseType"] = 18] = "MaxBaseType";
|
||||
})(BaseType || (BaseType = {}));
|
||||
23
tests/ts/reflection/base-type.ts
Normal file
23
tests/ts/reflection/base-type.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export enum BaseType {
|
||||
None = 0,
|
||||
UType = 1,
|
||||
Bool = 2,
|
||||
Byte = 3,
|
||||
UByte = 4,
|
||||
Short = 5,
|
||||
UShort = 6,
|
||||
Int = 7,
|
||||
UInt = 8,
|
||||
Long = 9,
|
||||
ULong = 10,
|
||||
Float = 11,
|
||||
Double = 12,
|
||||
String = 13,
|
||||
Vector = 14,
|
||||
Obj = 15,
|
||||
Union = 16,
|
||||
Array = 17,
|
||||
MaxBaseType = 18
|
||||
}
|
||||
110
tests/ts/reflection/enum-val.js
Normal file
110
tests/ts/reflection/enum-val.js
Normal file
@@ -0,0 +1,110 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
import { Type } from '../reflection/type.js';
|
||||
export class EnumVal {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsEnumVal(bb, obj) {
|
||||
return (obj || new EnumVal()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsEnumVal(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new EnumVal()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
name(optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
value() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
mutate_value(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
unionType(obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
return offset ? (obj || new Type()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
|
||||
}
|
||||
documentation(index, optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
|
||||
}
|
||||
documentationLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'reflection_EnumVal';
|
||||
}
|
||||
static startEnumVal(builder) {
|
||||
builder.startObject(5);
|
||||
}
|
||||
static addName(builder, nameOffset) {
|
||||
builder.addFieldOffset(0, nameOffset, 0);
|
||||
}
|
||||
static addValue(builder, value) {
|
||||
builder.addFieldInt64(1, value, BigInt('0'));
|
||||
}
|
||||
static addUnionType(builder, unionTypeOffset) {
|
||||
builder.addFieldOffset(3, unionTypeOffset, 0);
|
||||
}
|
||||
static addDocumentation(builder, documentationOffset) {
|
||||
builder.addFieldOffset(4, documentationOffset, 0);
|
||||
}
|
||||
static createDocumentationVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startDocumentationVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static endEnumVal(builder) {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4); // name
|
||||
return offset;
|
||||
}
|
||||
unpack() {
|
||||
return new EnumValT(this.name(), this.value(), (this.unionType() !== null ? this.unionType().unpack() : null), this.bb.createScalarList(this.documentation.bind(this), this.documentationLength()));
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.name = this.name();
|
||||
_o.value = this.value();
|
||||
_o.unionType = (this.unionType() !== null ? this.unionType().unpack() : null);
|
||||
_o.documentation = this.bb.createScalarList(this.documentation.bind(this), this.documentationLength());
|
||||
}
|
||||
}
|
||||
export class EnumValT {
|
||||
constructor(name = null, value = BigInt('0'), unionType = null, documentation = []) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.unionType = unionType;
|
||||
this.documentation = documentation;
|
||||
}
|
||||
pack(builder) {
|
||||
const name = (this.name !== null ? builder.createString(this.name) : 0);
|
||||
const unionType = (this.unionType !== null ? this.unionType.pack(builder) : 0);
|
||||
const documentation = EnumVal.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation));
|
||||
EnumVal.startEnumVal(builder);
|
||||
EnumVal.addName(builder, name);
|
||||
EnumVal.addValue(builder, this.value);
|
||||
EnumVal.addUnionType(builder, unionType);
|
||||
EnumVal.addDocumentation(builder, documentation);
|
||||
return EnumVal.endEnumVal(builder);
|
||||
}
|
||||
}
|
||||
149
tests/ts/reflection/enum-val.ts
Normal file
149
tests/ts/reflection/enum-val.ts
Normal file
@@ -0,0 +1,149 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { Type, TypeT } from '../reflection/type.js';
|
||||
|
||||
|
||||
export class EnumVal {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):EnumVal {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsEnumVal(bb:flatbuffers.ByteBuffer, obj?:EnumVal):EnumVal {
|
||||
return (obj || new EnumVal()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsEnumVal(bb:flatbuffers.ByteBuffer, obj?:EnumVal):EnumVal {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new EnumVal()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
name():string|null
|
||||
name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||
name(optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
value():bigint {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
|
||||
mutate_value(value:bigint):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
unionType(obj?:Type):Type|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
return offset ? (obj || new Type()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
|
||||
}
|
||||
|
||||
documentation(index: number):string
|
||||
documentation(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array
|
||||
documentation(index: number,optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb!.__string(this.bb!.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
documentationLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'reflection_EnumVal';
|
||||
}
|
||||
|
||||
static startEnumVal(builder:flatbuffers.Builder) {
|
||||
builder.startObject(5);
|
||||
}
|
||||
|
||||
static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(0, nameOffset, 0);
|
||||
}
|
||||
|
||||
static addValue(builder:flatbuffers.Builder, value:bigint) {
|
||||
builder.addFieldInt64(1, value, BigInt('0'));
|
||||
}
|
||||
|
||||
static addUnionType(builder:flatbuffers.Builder, unionTypeOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(3, unionTypeOffset, 0);
|
||||
}
|
||||
|
||||
static addDocumentation(builder:flatbuffers.Builder, documentationOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(4, documentationOffset, 0);
|
||||
}
|
||||
|
||||
static createDocumentationVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startDocumentationVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static endEnumVal(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4) // name
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
unpack(): EnumValT {
|
||||
return new EnumValT(
|
||||
this.name(),
|
||||
this.value(),
|
||||
(this.unionType() !== null ? this.unionType()!.unpack() : null),
|
||||
this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: EnumValT): void {
|
||||
_o.name = this.name();
|
||||
_o.value = this.value();
|
||||
_o.unionType = (this.unionType() !== null ? this.unionType()!.unpack() : null);
|
||||
_o.documentation = this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength());
|
||||
}
|
||||
}
|
||||
|
||||
export class EnumValT {
|
||||
constructor(
|
||||
public name: string|Uint8Array|null = null,
|
||||
public value: bigint = BigInt('0'),
|
||||
public unionType: TypeT|null = null,
|
||||
public documentation: (string)[] = []
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const name = (this.name !== null ? builder.createString(this.name!) : 0);
|
||||
const unionType = (this.unionType !== null ? this.unionType!.pack(builder) : 0);
|
||||
const documentation = EnumVal.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation));
|
||||
|
||||
EnumVal.startEnumVal(builder);
|
||||
EnumVal.addName(builder, name);
|
||||
EnumVal.addValue(builder, this.value);
|
||||
EnumVal.addUnionType(builder, unionType);
|
||||
EnumVal.addDocumentation(builder, documentation);
|
||||
|
||||
return EnumVal.endEnumVal(builder);
|
||||
}
|
||||
}
|
||||
175
tests/ts/reflection/enum.js
Normal file
175
tests/ts/reflection/enum.js
Normal file
@@ -0,0 +1,175 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
import { EnumVal } from '../reflection/enum-val.js';
|
||||
import { KeyValue } from '../reflection/key-value.js';
|
||||
import { Type } from '../reflection/type.js';
|
||||
export class Enum {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsEnum(bb, obj) {
|
||||
return (obj || new Enum()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsEnum(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Enum()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
name(optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
values(index, obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? (obj || new EnumVal()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
||||
}
|
||||
valuesLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
isUnion() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false;
|
||||
}
|
||||
mutate_is_union(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt8(this.bb_pos + offset, +value);
|
||||
return true;
|
||||
}
|
||||
underlyingType(obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
return offset ? (obj || new Type()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
|
||||
}
|
||||
attributes(index, obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
return offset ? (obj || new KeyValue()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
||||
}
|
||||
attributesLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
documentation(index, optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
|
||||
}
|
||||
documentationLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
declarationFile(optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 16);
|
||||
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'reflection_Enum';
|
||||
}
|
||||
static startEnum(builder) {
|
||||
builder.startObject(7);
|
||||
}
|
||||
static addName(builder, nameOffset) {
|
||||
builder.addFieldOffset(0, nameOffset, 0);
|
||||
}
|
||||
static addValues(builder, valuesOffset) {
|
||||
builder.addFieldOffset(1, valuesOffset, 0);
|
||||
}
|
||||
static createValuesVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startValuesVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static addIsUnion(builder, isUnion) {
|
||||
builder.addFieldInt8(2, +isUnion, +false);
|
||||
}
|
||||
static addUnderlyingType(builder, underlyingTypeOffset) {
|
||||
builder.addFieldOffset(3, underlyingTypeOffset, 0);
|
||||
}
|
||||
static addAttributes(builder, attributesOffset) {
|
||||
builder.addFieldOffset(4, attributesOffset, 0);
|
||||
}
|
||||
static createAttributesVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startAttributesVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static addDocumentation(builder, documentationOffset) {
|
||||
builder.addFieldOffset(5, documentationOffset, 0);
|
||||
}
|
||||
static createDocumentationVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startDocumentationVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static addDeclarationFile(builder, declarationFileOffset) {
|
||||
builder.addFieldOffset(6, declarationFileOffset, 0);
|
||||
}
|
||||
static endEnum(builder) {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4); // name
|
||||
builder.requiredField(offset, 6); // values
|
||||
builder.requiredField(offset, 10); // underlying_type
|
||||
return offset;
|
||||
}
|
||||
unpack() {
|
||||
return new EnumT(this.name(), this.bb.createObjList(this.values.bind(this), this.valuesLength()), this.isUnion(), (this.underlyingType() !== null ? this.underlyingType().unpack() : null), this.bb.createObjList(this.attributes.bind(this), this.attributesLength()), this.bb.createScalarList(this.documentation.bind(this), this.documentationLength()), this.declarationFile());
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.name = this.name();
|
||||
_o.values = this.bb.createObjList(this.values.bind(this), this.valuesLength());
|
||||
_o.isUnion = this.isUnion();
|
||||
_o.underlyingType = (this.underlyingType() !== null ? this.underlyingType().unpack() : null);
|
||||
_o.attributes = this.bb.createObjList(this.attributes.bind(this), this.attributesLength());
|
||||
_o.documentation = this.bb.createScalarList(this.documentation.bind(this), this.documentationLength());
|
||||
_o.declarationFile = this.declarationFile();
|
||||
}
|
||||
}
|
||||
export class EnumT {
|
||||
constructor(name = null, values = [], isUnion = false, underlyingType = null, attributes = [], documentation = [], declarationFile = null) {
|
||||
this.name = name;
|
||||
this.values = values;
|
||||
this.isUnion = isUnion;
|
||||
this.underlyingType = underlyingType;
|
||||
this.attributes = attributes;
|
||||
this.documentation = documentation;
|
||||
this.declarationFile = declarationFile;
|
||||
}
|
||||
pack(builder) {
|
||||
const name = (this.name !== null ? builder.createString(this.name) : 0);
|
||||
const values = Enum.createValuesVector(builder, builder.createObjectOffsetList(this.values));
|
||||
const underlyingType = (this.underlyingType !== null ? this.underlyingType.pack(builder) : 0);
|
||||
const attributes = Enum.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes));
|
||||
const documentation = Enum.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation));
|
||||
const declarationFile = (this.declarationFile !== null ? builder.createString(this.declarationFile) : 0);
|
||||
Enum.startEnum(builder);
|
||||
Enum.addName(builder, name);
|
||||
Enum.addValues(builder, values);
|
||||
Enum.addIsUnion(builder, this.isUnion);
|
||||
Enum.addUnderlyingType(builder, underlyingType);
|
||||
Enum.addAttributes(builder, attributes);
|
||||
Enum.addDocumentation(builder, documentation);
|
||||
Enum.addDeclarationFile(builder, declarationFile);
|
||||
return Enum.endEnum(builder);
|
||||
}
|
||||
}
|
||||
234
tests/ts/reflection/enum.ts
Normal file
234
tests/ts/reflection/enum.ts
Normal file
@@ -0,0 +1,234 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { EnumVal, EnumValT } from '../reflection/enum-val.js';
|
||||
import { KeyValue, KeyValueT } from '../reflection/key-value.js';
|
||||
import { Type, TypeT } from '../reflection/type.js';
|
||||
|
||||
|
||||
export class Enum {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Enum {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsEnum(bb:flatbuffers.ByteBuffer, obj?:Enum):Enum {
|
||||
return (obj || new Enum()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsEnum(bb:flatbuffers.ByteBuffer, obj?:Enum):Enum {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Enum()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
name():string|null
|
||||
name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||
name(optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
values(index: number, obj?:EnumVal):EnumVal|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? (obj || new EnumVal()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
|
||||
}
|
||||
|
||||
valuesLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
isUnion():boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false;
|
||||
}
|
||||
|
||||
mutate_is_union(value:boolean):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt8(this.bb_pos + offset, +value);
|
||||
return true;
|
||||
}
|
||||
|
||||
underlyingType(obj?:Type):Type|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
return offset ? (obj || new Type()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
|
||||
}
|
||||
|
||||
attributes(index: number, obj?:KeyValue):KeyValue|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? (obj || new KeyValue()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
|
||||
}
|
||||
|
||||
attributesLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
documentation(index: number):string
|
||||
documentation(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array
|
||||
documentation(index: number,optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb!.__string(this.bb!.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
documentationLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* File that this Enum is declared in.
|
||||
*/
|
||||
declarationFile():string|null
|
||||
declarationFile(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||
declarationFile(optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 16);
|
||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'reflection_Enum';
|
||||
}
|
||||
|
||||
static startEnum(builder:flatbuffers.Builder) {
|
||||
builder.startObject(7);
|
||||
}
|
||||
|
||||
static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(0, nameOffset, 0);
|
||||
}
|
||||
|
||||
static addValues(builder:flatbuffers.Builder, valuesOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(1, valuesOffset, 0);
|
||||
}
|
||||
|
||||
static createValuesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startValuesVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static addIsUnion(builder:flatbuffers.Builder, isUnion:boolean) {
|
||||
builder.addFieldInt8(2, +isUnion, +false);
|
||||
}
|
||||
|
||||
static addUnderlyingType(builder:flatbuffers.Builder, underlyingTypeOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(3, underlyingTypeOffset, 0);
|
||||
}
|
||||
|
||||
static addAttributes(builder:flatbuffers.Builder, attributesOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(4, attributesOffset, 0);
|
||||
}
|
||||
|
||||
static createAttributesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startAttributesVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static addDocumentation(builder:flatbuffers.Builder, documentationOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(5, documentationOffset, 0);
|
||||
}
|
||||
|
||||
static createDocumentationVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startDocumentationVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static addDeclarationFile(builder:flatbuffers.Builder, declarationFileOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(6, declarationFileOffset, 0);
|
||||
}
|
||||
|
||||
static endEnum(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4) // name
|
||||
builder.requiredField(offset, 6) // values
|
||||
builder.requiredField(offset, 10) // underlying_type
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
unpack(): EnumT {
|
||||
return new EnumT(
|
||||
this.name(),
|
||||
this.bb!.createObjList(this.values.bind(this), this.valuesLength()),
|
||||
this.isUnion(),
|
||||
(this.underlyingType() !== null ? this.underlyingType()!.unpack() : null),
|
||||
this.bb!.createObjList(this.attributes.bind(this), this.attributesLength()),
|
||||
this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength()),
|
||||
this.declarationFile()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: EnumT): void {
|
||||
_o.name = this.name();
|
||||
_o.values = this.bb!.createObjList(this.values.bind(this), this.valuesLength());
|
||||
_o.isUnion = this.isUnion();
|
||||
_o.underlyingType = (this.underlyingType() !== null ? this.underlyingType()!.unpack() : null);
|
||||
_o.attributes = this.bb!.createObjList(this.attributes.bind(this), this.attributesLength());
|
||||
_o.documentation = this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength());
|
||||
_o.declarationFile = this.declarationFile();
|
||||
}
|
||||
}
|
||||
|
||||
export class EnumT {
|
||||
constructor(
|
||||
public name: string|Uint8Array|null = null,
|
||||
public values: (EnumValT)[] = [],
|
||||
public isUnion: boolean = false,
|
||||
public underlyingType: TypeT|null = null,
|
||||
public attributes: (KeyValueT)[] = [],
|
||||
public documentation: (string)[] = [],
|
||||
public declarationFile: string|Uint8Array|null = null
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const name = (this.name !== null ? builder.createString(this.name!) : 0);
|
||||
const values = Enum.createValuesVector(builder, builder.createObjectOffsetList(this.values));
|
||||
const underlyingType = (this.underlyingType !== null ? this.underlyingType!.pack(builder) : 0);
|
||||
const attributes = Enum.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes));
|
||||
const documentation = Enum.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation));
|
||||
const declarationFile = (this.declarationFile !== null ? builder.createString(this.declarationFile!) : 0);
|
||||
|
||||
Enum.startEnum(builder);
|
||||
Enum.addName(builder, name);
|
||||
Enum.addValues(builder, values);
|
||||
Enum.addIsUnion(builder, this.isUnion);
|
||||
Enum.addUnderlyingType(builder, underlyingType);
|
||||
Enum.addAttributes(builder, attributes);
|
||||
Enum.addDocumentation(builder, documentation);
|
||||
Enum.addDeclarationFile(builder, declarationFile);
|
||||
|
||||
return Enum.endEnum(builder);
|
||||
}
|
||||
}
|
||||
284
tests/ts/reflection/field.js
Normal file
284
tests/ts/reflection/field.js
Normal file
@@ -0,0 +1,284 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
import { KeyValue } from '../reflection/key-value.js';
|
||||
import { Type } from '../reflection/type.js';
|
||||
export class Field {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsField(bb, obj) {
|
||||
return (obj || new Field()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsField(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Field()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
name(optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
type(obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? (obj || new Type()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
|
||||
}
|
||||
id() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb.readUint16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_id(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeUint16(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
offset() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb.readUint16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_offset(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeUint16(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
defaultInteger() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
mutate_default_integer(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
defaultReal() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb.readFloat64(this.bb_pos + offset) : 0.0;
|
||||
}
|
||||
mutate_default_real(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeFloat64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
deprecated() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 16);
|
||||
return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false;
|
||||
}
|
||||
mutate_deprecated(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 16);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt8(this.bb_pos + offset, +value);
|
||||
return true;
|
||||
}
|
||||
required() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 18);
|
||||
return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false;
|
||||
}
|
||||
mutate_required(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 18);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt8(this.bb_pos + offset, +value);
|
||||
return true;
|
||||
}
|
||||
key() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 20);
|
||||
return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false;
|
||||
}
|
||||
mutate_key(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 20);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt8(this.bb_pos + offset, +value);
|
||||
return true;
|
||||
}
|
||||
attributes(index, obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 22);
|
||||
return offset ? (obj || new KeyValue()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
||||
}
|
||||
attributesLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 22);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
documentation(index, optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 24);
|
||||
return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
|
||||
}
|
||||
documentationLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 24);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
optional() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 26);
|
||||
return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false;
|
||||
}
|
||||
mutate_optional(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 26);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt8(this.bb_pos + offset, +value);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Number of padding octets to always add after this field. Structs only.
|
||||
*/
|
||||
padding() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 28);
|
||||
return offset ? this.bb.readUint16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_padding(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 28);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeUint16(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'reflection_Field';
|
||||
}
|
||||
static startField(builder) {
|
||||
builder.startObject(13);
|
||||
}
|
||||
static addName(builder, nameOffset) {
|
||||
builder.addFieldOffset(0, nameOffset, 0);
|
||||
}
|
||||
static addType(builder, typeOffset) {
|
||||
builder.addFieldOffset(1, typeOffset, 0);
|
||||
}
|
||||
static addId(builder, id) {
|
||||
builder.addFieldInt16(2, id, 0);
|
||||
}
|
||||
static addOffset(builder, offset) {
|
||||
builder.addFieldInt16(3, offset, 0);
|
||||
}
|
||||
static addDefaultInteger(builder, defaultInteger) {
|
||||
builder.addFieldInt64(4, defaultInteger, BigInt('0'));
|
||||
}
|
||||
static addDefaultReal(builder, defaultReal) {
|
||||
builder.addFieldFloat64(5, defaultReal, 0.0);
|
||||
}
|
||||
static addDeprecated(builder, deprecated) {
|
||||
builder.addFieldInt8(6, +deprecated, +false);
|
||||
}
|
||||
static addRequired(builder, required) {
|
||||
builder.addFieldInt8(7, +required, +false);
|
||||
}
|
||||
static addKey(builder, key) {
|
||||
builder.addFieldInt8(8, +key, +false);
|
||||
}
|
||||
static addAttributes(builder, attributesOffset) {
|
||||
builder.addFieldOffset(9, attributesOffset, 0);
|
||||
}
|
||||
static createAttributesVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startAttributesVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static addDocumentation(builder, documentationOffset) {
|
||||
builder.addFieldOffset(10, documentationOffset, 0);
|
||||
}
|
||||
static createDocumentationVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startDocumentationVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static addOptional(builder, optional) {
|
||||
builder.addFieldInt8(11, +optional, +false);
|
||||
}
|
||||
static addPadding(builder, padding) {
|
||||
builder.addFieldInt16(12, padding, 0);
|
||||
}
|
||||
static endField(builder) {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4); // name
|
||||
builder.requiredField(offset, 6); // type
|
||||
return offset;
|
||||
}
|
||||
unpack() {
|
||||
return new FieldT(this.name(), (this.type() !== null ? this.type().unpack() : null), this.id(), this.offset(), this.defaultInteger(), this.defaultReal(), this.deprecated(), this.required(), this.key(), this.bb.createObjList(this.attributes.bind(this), this.attributesLength()), this.bb.createScalarList(this.documentation.bind(this), this.documentationLength()), this.optional(), this.padding());
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.name = this.name();
|
||||
_o.type = (this.type() !== null ? this.type().unpack() : null);
|
||||
_o.id = this.id();
|
||||
_o.offset = this.offset();
|
||||
_o.defaultInteger = this.defaultInteger();
|
||||
_o.defaultReal = this.defaultReal();
|
||||
_o.deprecated = this.deprecated();
|
||||
_o.required = this.required();
|
||||
_o.key = this.key();
|
||||
_o.attributes = this.bb.createObjList(this.attributes.bind(this), this.attributesLength());
|
||||
_o.documentation = this.bb.createScalarList(this.documentation.bind(this), this.documentationLength());
|
||||
_o.optional = this.optional();
|
||||
_o.padding = this.padding();
|
||||
}
|
||||
}
|
||||
export class FieldT {
|
||||
constructor(name = null, type = null, id = 0, offset = 0, defaultInteger = BigInt('0'), defaultReal = 0.0, deprecated = false, required = false, key = false, attributes = [], documentation = [], optional = false, padding = 0) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.offset = offset;
|
||||
this.defaultInteger = defaultInteger;
|
||||
this.defaultReal = defaultReal;
|
||||
this.deprecated = deprecated;
|
||||
this.required = required;
|
||||
this.key = key;
|
||||
this.attributes = attributes;
|
||||
this.documentation = documentation;
|
||||
this.optional = optional;
|
||||
this.padding = padding;
|
||||
}
|
||||
pack(builder) {
|
||||
const name = (this.name !== null ? builder.createString(this.name) : 0);
|
||||
const type = (this.type !== null ? this.type.pack(builder) : 0);
|
||||
const attributes = Field.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes));
|
||||
const documentation = Field.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation));
|
||||
Field.startField(builder);
|
||||
Field.addName(builder, name);
|
||||
Field.addType(builder, type);
|
||||
Field.addId(builder, this.id);
|
||||
Field.addOffset(builder, this.offset);
|
||||
Field.addDefaultInteger(builder, this.defaultInteger);
|
||||
Field.addDefaultReal(builder, this.defaultReal);
|
||||
Field.addDeprecated(builder, this.deprecated);
|
||||
Field.addRequired(builder, this.required);
|
||||
Field.addKey(builder, this.key);
|
||||
Field.addAttributes(builder, attributes);
|
||||
Field.addDocumentation(builder, documentation);
|
||||
Field.addOptional(builder, this.optional);
|
||||
Field.addPadding(builder, this.padding);
|
||||
return Field.endField(builder);
|
||||
}
|
||||
}
|
||||
377
tests/ts/reflection/field.ts
Normal file
377
tests/ts/reflection/field.ts
Normal file
@@ -0,0 +1,377 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { KeyValue, KeyValueT } from '../reflection/key-value.js';
|
||||
import { Type, TypeT } from '../reflection/type.js';
|
||||
|
||||
|
||||
export class Field {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Field {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsField(bb:flatbuffers.ByteBuffer, obj?:Field):Field {
|
||||
return (obj || new Field()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsField(bb:flatbuffers.ByteBuffer, obj?:Field):Field {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Field()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
name():string|null
|
||||
name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||
name(optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
type(obj?:Type):Type|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? (obj || new Type()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
|
||||
}
|
||||
|
||||
id():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_id(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeUint16(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
offset():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_offset(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeUint16(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
defaultInteger():bigint {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
|
||||
mutate_default_integer(value:bigint):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
defaultReal():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb!.readFloat64(this.bb_pos + offset) : 0.0;
|
||||
}
|
||||
|
||||
mutate_default_real(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeFloat64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
deprecated():boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 16);
|
||||
return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false;
|
||||
}
|
||||
|
||||
mutate_deprecated(value:boolean):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 16);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt8(this.bb_pos + offset, +value);
|
||||
return true;
|
||||
}
|
||||
|
||||
required():boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 18);
|
||||
return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false;
|
||||
}
|
||||
|
||||
mutate_required(value:boolean):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 18);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt8(this.bb_pos + offset, +value);
|
||||
return true;
|
||||
}
|
||||
|
||||
key():boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 20);
|
||||
return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false;
|
||||
}
|
||||
|
||||
mutate_key(value:boolean):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 20);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt8(this.bb_pos + offset, +value);
|
||||
return true;
|
||||
}
|
||||
|
||||
attributes(index: number, obj?:KeyValue):KeyValue|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 22);
|
||||
return offset ? (obj || new KeyValue()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
|
||||
}
|
||||
|
||||
attributesLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 22);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
documentation(index: number):string
|
||||
documentation(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array
|
||||
documentation(index: number,optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 24);
|
||||
return offset ? this.bb!.__string(this.bb!.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
documentationLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 24);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
optional():boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 26);
|
||||
return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false;
|
||||
}
|
||||
|
||||
mutate_optional(value:boolean):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 26);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt8(this.bb_pos + offset, +value);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of padding octets to always add after this field. Structs only.
|
||||
*/
|
||||
padding():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 28);
|
||||
return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_padding(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 28);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeUint16(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'reflection_Field';
|
||||
}
|
||||
|
||||
static startField(builder:flatbuffers.Builder) {
|
||||
builder.startObject(13);
|
||||
}
|
||||
|
||||
static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(0, nameOffset, 0);
|
||||
}
|
||||
|
||||
static addType(builder:flatbuffers.Builder, typeOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(1, typeOffset, 0);
|
||||
}
|
||||
|
||||
static addId(builder:flatbuffers.Builder, id:number) {
|
||||
builder.addFieldInt16(2, id, 0);
|
||||
}
|
||||
|
||||
static addOffset(builder:flatbuffers.Builder, offset:number) {
|
||||
builder.addFieldInt16(3, offset, 0);
|
||||
}
|
||||
|
||||
static addDefaultInteger(builder:flatbuffers.Builder, defaultInteger:bigint) {
|
||||
builder.addFieldInt64(4, defaultInteger, BigInt('0'));
|
||||
}
|
||||
|
||||
static addDefaultReal(builder:flatbuffers.Builder, defaultReal:number) {
|
||||
builder.addFieldFloat64(5, defaultReal, 0.0);
|
||||
}
|
||||
|
||||
static addDeprecated(builder:flatbuffers.Builder, deprecated:boolean) {
|
||||
builder.addFieldInt8(6, +deprecated, +false);
|
||||
}
|
||||
|
||||
static addRequired(builder:flatbuffers.Builder, required:boolean) {
|
||||
builder.addFieldInt8(7, +required, +false);
|
||||
}
|
||||
|
||||
static addKey(builder:flatbuffers.Builder, key:boolean) {
|
||||
builder.addFieldInt8(8, +key, +false);
|
||||
}
|
||||
|
||||
static addAttributes(builder:flatbuffers.Builder, attributesOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(9, attributesOffset, 0);
|
||||
}
|
||||
|
||||
static createAttributesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startAttributesVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static addDocumentation(builder:flatbuffers.Builder, documentationOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(10, documentationOffset, 0);
|
||||
}
|
||||
|
||||
static createDocumentationVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startDocumentationVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static addOptional(builder:flatbuffers.Builder, optional:boolean) {
|
||||
builder.addFieldInt8(11, +optional, +false);
|
||||
}
|
||||
|
||||
static addPadding(builder:flatbuffers.Builder, padding:number) {
|
||||
builder.addFieldInt16(12, padding, 0);
|
||||
}
|
||||
|
||||
static endField(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4) // name
|
||||
builder.requiredField(offset, 6) // type
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
unpack(): FieldT {
|
||||
return new FieldT(
|
||||
this.name(),
|
||||
(this.type() !== null ? this.type()!.unpack() : null),
|
||||
this.id(),
|
||||
this.offset(),
|
||||
this.defaultInteger(),
|
||||
this.defaultReal(),
|
||||
this.deprecated(),
|
||||
this.required(),
|
||||
this.key(),
|
||||
this.bb!.createObjList(this.attributes.bind(this), this.attributesLength()),
|
||||
this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength()),
|
||||
this.optional(),
|
||||
this.padding()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: FieldT): void {
|
||||
_o.name = this.name();
|
||||
_o.type = (this.type() !== null ? this.type()!.unpack() : null);
|
||||
_o.id = this.id();
|
||||
_o.offset = this.offset();
|
||||
_o.defaultInteger = this.defaultInteger();
|
||||
_o.defaultReal = this.defaultReal();
|
||||
_o.deprecated = this.deprecated();
|
||||
_o.required = this.required();
|
||||
_o.key = this.key();
|
||||
_o.attributes = this.bb!.createObjList(this.attributes.bind(this), this.attributesLength());
|
||||
_o.documentation = this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength());
|
||||
_o.optional = this.optional();
|
||||
_o.padding = this.padding();
|
||||
}
|
||||
}
|
||||
|
||||
export class FieldT {
|
||||
constructor(
|
||||
public name: string|Uint8Array|null = null,
|
||||
public type: TypeT|null = null,
|
||||
public id: number = 0,
|
||||
public offset: number = 0,
|
||||
public defaultInteger: bigint = BigInt('0'),
|
||||
public defaultReal: number = 0.0,
|
||||
public deprecated: boolean = false,
|
||||
public required: boolean = false,
|
||||
public key: boolean = false,
|
||||
public attributes: (KeyValueT)[] = [],
|
||||
public documentation: (string)[] = [],
|
||||
public optional: boolean = false,
|
||||
public padding: number = 0
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const name = (this.name !== null ? builder.createString(this.name!) : 0);
|
||||
const type = (this.type !== null ? this.type!.pack(builder) : 0);
|
||||
const attributes = Field.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes));
|
||||
const documentation = Field.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation));
|
||||
|
||||
Field.startField(builder);
|
||||
Field.addName(builder, name);
|
||||
Field.addType(builder, type);
|
||||
Field.addId(builder, this.id);
|
||||
Field.addOffset(builder, this.offset);
|
||||
Field.addDefaultInteger(builder, this.defaultInteger);
|
||||
Field.addDefaultReal(builder, this.defaultReal);
|
||||
Field.addDeprecated(builder, this.deprecated);
|
||||
Field.addRequired(builder, this.required);
|
||||
Field.addKey(builder, this.key);
|
||||
Field.addAttributes(builder, attributes);
|
||||
Field.addDocumentation(builder, documentation);
|
||||
Field.addOptional(builder, this.optional);
|
||||
Field.addPadding(builder, this.padding);
|
||||
|
||||
return Field.endField(builder);
|
||||
}
|
||||
}
|
||||
69
tests/ts/reflection/key-value.js
Normal file
69
tests/ts/reflection/key-value.js
Normal file
@@ -0,0 +1,69 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
export class KeyValue {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsKeyValue(bb, obj) {
|
||||
return (obj || new KeyValue()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsKeyValue(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new KeyValue()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
key(optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
value(optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'reflection_KeyValue';
|
||||
}
|
||||
static startKeyValue(builder) {
|
||||
builder.startObject(2);
|
||||
}
|
||||
static addKey(builder, keyOffset) {
|
||||
builder.addFieldOffset(0, keyOffset, 0);
|
||||
}
|
||||
static addValue(builder, valueOffset) {
|
||||
builder.addFieldOffset(1, valueOffset, 0);
|
||||
}
|
||||
static endKeyValue(builder) {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4); // key
|
||||
return offset;
|
||||
}
|
||||
static createKeyValue(builder, keyOffset, valueOffset) {
|
||||
KeyValue.startKeyValue(builder);
|
||||
KeyValue.addKey(builder, keyOffset);
|
||||
KeyValue.addValue(builder, valueOffset);
|
||||
return KeyValue.endKeyValue(builder);
|
||||
}
|
||||
unpack() {
|
||||
return new KeyValueT(this.key(), this.value());
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.key = this.key();
|
||||
_o.value = this.value();
|
||||
}
|
||||
}
|
||||
export class KeyValueT {
|
||||
constructor(key = null, value = null) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
pack(builder) {
|
||||
const key = (this.key !== null ? builder.createString(this.key) : 0);
|
||||
const value = (this.value !== null ? builder.createString(this.value) : 0);
|
||||
return KeyValue.createKeyValue(builder, key, value);
|
||||
}
|
||||
}
|
||||
98
tests/ts/reflection/key-value.ts
Normal file
98
tests/ts/reflection/key-value.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
export class KeyValue {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):KeyValue {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsKeyValue(bb:flatbuffers.ByteBuffer, obj?:KeyValue):KeyValue {
|
||||
return (obj || new KeyValue()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsKeyValue(bb:flatbuffers.ByteBuffer, obj?:KeyValue):KeyValue {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new KeyValue()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
key():string|null
|
||||
key(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||
key(optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
value():string|null
|
||||
value(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||
value(optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'reflection_KeyValue';
|
||||
}
|
||||
|
||||
static startKeyValue(builder:flatbuffers.Builder) {
|
||||
builder.startObject(2);
|
||||
}
|
||||
|
||||
static addKey(builder:flatbuffers.Builder, keyOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(0, keyOffset, 0);
|
||||
}
|
||||
|
||||
static addValue(builder:flatbuffers.Builder, valueOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(1, valueOffset, 0);
|
||||
}
|
||||
|
||||
static endKeyValue(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4) // key
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createKeyValue(builder:flatbuffers.Builder, keyOffset:flatbuffers.Offset, valueOffset:flatbuffers.Offset):flatbuffers.Offset {
|
||||
KeyValue.startKeyValue(builder);
|
||||
KeyValue.addKey(builder, keyOffset);
|
||||
KeyValue.addValue(builder, valueOffset);
|
||||
return KeyValue.endKeyValue(builder);
|
||||
}
|
||||
|
||||
unpack(): KeyValueT {
|
||||
return new KeyValueT(
|
||||
this.key(),
|
||||
this.value()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: KeyValueT): void {
|
||||
_o.key = this.key();
|
||||
_o.value = this.value();
|
||||
}
|
||||
}
|
||||
|
||||
export class KeyValueT {
|
||||
constructor(
|
||||
public key: string|Uint8Array|null = null,
|
||||
public value: string|Uint8Array|null = null
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const key = (this.key !== null ? builder.createString(this.key!) : 0);
|
||||
const value = (this.value !== null ? builder.createString(this.value!) : 0);
|
||||
|
||||
return KeyValue.createKeyValue(builder,
|
||||
key,
|
||||
value
|
||||
);
|
||||
}
|
||||
}
|
||||
201
tests/ts/reflection/object.js
Normal file
201
tests/ts/reflection/object.js
Normal file
@@ -0,0 +1,201 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
import { Field } from '../reflection/field.js';
|
||||
import { KeyValue } from '../reflection/key-value.js';
|
||||
export class Object_ {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsObject(bb, obj) {
|
||||
return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsObject(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
name(optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
fields(index, obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? (obj || new Field()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
||||
}
|
||||
fieldsLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
isStruct() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false;
|
||||
}
|
||||
mutate_is_struct(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt8(this.bb_pos + offset, +value);
|
||||
return true;
|
||||
}
|
||||
minalign() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_minalign(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
bytesize() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_bytesize(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
attributes(index, obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
return offset ? (obj || new KeyValue()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
||||
}
|
||||
attributesLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
documentation(index, optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 16);
|
||||
return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
|
||||
}
|
||||
documentationLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 16);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
declarationFile(optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 18);
|
||||
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'reflection_Object';
|
||||
}
|
||||
static startObject(builder) {
|
||||
builder.startObject(8);
|
||||
}
|
||||
static addName(builder, nameOffset) {
|
||||
builder.addFieldOffset(0, nameOffset, 0);
|
||||
}
|
||||
static addFields(builder, fieldsOffset) {
|
||||
builder.addFieldOffset(1, fieldsOffset, 0);
|
||||
}
|
||||
static createFieldsVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startFieldsVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static addIsStruct(builder, isStruct) {
|
||||
builder.addFieldInt8(2, +isStruct, +false);
|
||||
}
|
||||
static addMinalign(builder, minalign) {
|
||||
builder.addFieldInt32(3, minalign, 0);
|
||||
}
|
||||
static addBytesize(builder, bytesize) {
|
||||
builder.addFieldInt32(4, bytesize, 0);
|
||||
}
|
||||
static addAttributes(builder, attributesOffset) {
|
||||
builder.addFieldOffset(5, attributesOffset, 0);
|
||||
}
|
||||
static createAttributesVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startAttributesVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static addDocumentation(builder, documentationOffset) {
|
||||
builder.addFieldOffset(6, documentationOffset, 0);
|
||||
}
|
||||
static createDocumentationVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startDocumentationVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static addDeclarationFile(builder, declarationFileOffset) {
|
||||
builder.addFieldOffset(7, declarationFileOffset, 0);
|
||||
}
|
||||
static endObject(builder) {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4); // name
|
||||
builder.requiredField(offset, 6); // fields
|
||||
return offset;
|
||||
}
|
||||
static createObject(builder, nameOffset, fieldsOffset, isStruct, minalign, bytesize, attributesOffset, documentationOffset, declarationFileOffset) {
|
||||
Object_.startObject(builder);
|
||||
Object_.addName(builder, nameOffset);
|
||||
Object_.addFields(builder, fieldsOffset);
|
||||
Object_.addIsStruct(builder, isStruct);
|
||||
Object_.addMinalign(builder, minalign);
|
||||
Object_.addBytesize(builder, bytesize);
|
||||
Object_.addAttributes(builder, attributesOffset);
|
||||
Object_.addDocumentation(builder, documentationOffset);
|
||||
Object_.addDeclarationFile(builder, declarationFileOffset);
|
||||
return Object_.endObject(builder);
|
||||
}
|
||||
unpack() {
|
||||
return new Object_T(this.name(), this.bb.createObjList(this.fields.bind(this), this.fieldsLength()), this.isStruct(), this.minalign(), this.bytesize(), this.bb.createObjList(this.attributes.bind(this), this.attributesLength()), this.bb.createScalarList(this.documentation.bind(this), this.documentationLength()), this.declarationFile());
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.name = this.name();
|
||||
_o.fields = this.bb.createObjList(this.fields.bind(this), this.fieldsLength());
|
||||
_o.isStruct = this.isStruct();
|
||||
_o.minalign = this.minalign();
|
||||
_o.bytesize = this.bytesize();
|
||||
_o.attributes = this.bb.createObjList(this.attributes.bind(this), this.attributesLength());
|
||||
_o.documentation = this.bb.createScalarList(this.documentation.bind(this), this.documentationLength());
|
||||
_o.declarationFile = this.declarationFile();
|
||||
}
|
||||
}
|
||||
export class Object_T {
|
||||
constructor(name = null, fields = [], isStruct = false, minalign = 0, bytesize = 0, attributes = [], documentation = [], declarationFile = null) {
|
||||
this.name = name;
|
||||
this.fields = fields;
|
||||
this.isStruct = isStruct;
|
||||
this.minalign = minalign;
|
||||
this.bytesize = bytesize;
|
||||
this.attributes = attributes;
|
||||
this.documentation = documentation;
|
||||
this.declarationFile = declarationFile;
|
||||
}
|
||||
pack(builder) {
|
||||
const name = (this.name !== null ? builder.createString(this.name) : 0);
|
||||
const fields = Object_.createFieldsVector(builder, builder.createObjectOffsetList(this.fields));
|
||||
const attributes = Object_.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes));
|
||||
const documentation = Object_.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation));
|
||||
const declarationFile = (this.declarationFile !== null ? builder.createString(this.declarationFile) : 0);
|
||||
return Object_.createObject(builder, name, fields, this.isStruct, this.minalign, this.bytesize, attributes, documentation, declarationFile);
|
||||
}
|
||||
}
|
||||
277
tests/ts/reflection/object.ts
Normal file
277
tests/ts/reflection/object.ts
Normal file
@@ -0,0 +1,277 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { Field, FieldT } from '../reflection/field.js';
|
||||
import { KeyValue, KeyValueT } from '../reflection/key-value.js';
|
||||
|
||||
|
||||
export class Object_ {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Object_ {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsObject(bb:flatbuffers.ByteBuffer, obj?:Object_):Object_ {
|
||||
return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsObject(bb:flatbuffers.ByteBuffer, obj?:Object_):Object_ {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
name():string|null
|
||||
name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||
name(optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
fields(index: number, obj?:Field):Field|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? (obj || new Field()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
|
||||
}
|
||||
|
||||
fieldsLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
isStruct():boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false;
|
||||
}
|
||||
|
||||
mutate_is_struct(value:boolean):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt8(this.bb_pos + offset, +value);
|
||||
return true;
|
||||
}
|
||||
|
||||
minalign():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_minalign(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
bytesize():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_bytesize(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
attributes(index: number, obj?:KeyValue):KeyValue|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
return offset ? (obj || new KeyValue()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
|
||||
}
|
||||
|
||||
attributesLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
documentation(index: number):string
|
||||
documentation(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array
|
||||
documentation(index: number,optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 16);
|
||||
return offset ? this.bb!.__string(this.bb!.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
documentationLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 16);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* File that this Object is declared in.
|
||||
*/
|
||||
declarationFile():string|null
|
||||
declarationFile(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||
declarationFile(optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 18);
|
||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'reflection_Object';
|
||||
}
|
||||
|
||||
static startObject(builder:flatbuffers.Builder) {
|
||||
builder.startObject(8);
|
||||
}
|
||||
|
||||
static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(0, nameOffset, 0);
|
||||
}
|
||||
|
||||
static addFields(builder:flatbuffers.Builder, fieldsOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(1, fieldsOffset, 0);
|
||||
}
|
||||
|
||||
static createFieldsVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startFieldsVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static addIsStruct(builder:flatbuffers.Builder, isStruct:boolean) {
|
||||
builder.addFieldInt8(2, +isStruct, +false);
|
||||
}
|
||||
|
||||
static addMinalign(builder:flatbuffers.Builder, minalign:number) {
|
||||
builder.addFieldInt32(3, minalign, 0);
|
||||
}
|
||||
|
||||
static addBytesize(builder:flatbuffers.Builder, bytesize:number) {
|
||||
builder.addFieldInt32(4, bytesize, 0);
|
||||
}
|
||||
|
||||
static addAttributes(builder:flatbuffers.Builder, attributesOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(5, attributesOffset, 0);
|
||||
}
|
||||
|
||||
static createAttributesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startAttributesVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static addDocumentation(builder:flatbuffers.Builder, documentationOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(6, documentationOffset, 0);
|
||||
}
|
||||
|
||||
static createDocumentationVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startDocumentationVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static addDeclarationFile(builder:flatbuffers.Builder, declarationFileOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(7, declarationFileOffset, 0);
|
||||
}
|
||||
|
||||
static endObject(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4) // name
|
||||
builder.requiredField(offset, 6) // fields
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createObject(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset, fieldsOffset:flatbuffers.Offset, isStruct:boolean, minalign:number, bytesize:number, attributesOffset:flatbuffers.Offset, documentationOffset:flatbuffers.Offset, declarationFileOffset:flatbuffers.Offset):flatbuffers.Offset {
|
||||
Object_.startObject(builder);
|
||||
Object_.addName(builder, nameOffset);
|
||||
Object_.addFields(builder, fieldsOffset);
|
||||
Object_.addIsStruct(builder, isStruct);
|
||||
Object_.addMinalign(builder, minalign);
|
||||
Object_.addBytesize(builder, bytesize);
|
||||
Object_.addAttributes(builder, attributesOffset);
|
||||
Object_.addDocumentation(builder, documentationOffset);
|
||||
Object_.addDeclarationFile(builder, declarationFileOffset);
|
||||
return Object_.endObject(builder);
|
||||
}
|
||||
|
||||
unpack(): Object_T {
|
||||
return new Object_T(
|
||||
this.name(),
|
||||
this.bb!.createObjList(this.fields.bind(this), this.fieldsLength()),
|
||||
this.isStruct(),
|
||||
this.minalign(),
|
||||
this.bytesize(),
|
||||
this.bb!.createObjList(this.attributes.bind(this), this.attributesLength()),
|
||||
this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength()),
|
||||
this.declarationFile()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: Object_T): void {
|
||||
_o.name = this.name();
|
||||
_o.fields = this.bb!.createObjList(this.fields.bind(this), this.fieldsLength());
|
||||
_o.isStruct = this.isStruct();
|
||||
_o.minalign = this.minalign();
|
||||
_o.bytesize = this.bytesize();
|
||||
_o.attributes = this.bb!.createObjList(this.attributes.bind(this), this.attributesLength());
|
||||
_o.documentation = this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength());
|
||||
_o.declarationFile = this.declarationFile();
|
||||
}
|
||||
}
|
||||
|
||||
export class Object_T {
|
||||
constructor(
|
||||
public name: string|Uint8Array|null = null,
|
||||
public fields: (FieldT)[] = [],
|
||||
public isStruct: boolean = false,
|
||||
public minalign: number = 0,
|
||||
public bytesize: number = 0,
|
||||
public attributes: (KeyValueT)[] = [],
|
||||
public documentation: (string)[] = [],
|
||||
public declarationFile: string|Uint8Array|null = null
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const name = (this.name !== null ? builder.createString(this.name!) : 0);
|
||||
const fields = Object_.createFieldsVector(builder, builder.createObjectOffsetList(this.fields));
|
||||
const attributes = Object_.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes));
|
||||
const documentation = Object_.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation));
|
||||
const declarationFile = (this.declarationFile !== null ? builder.createString(this.declarationFile!) : 0);
|
||||
|
||||
return Object_.createObject(builder,
|
||||
name,
|
||||
fields,
|
||||
this.isStruct,
|
||||
this.minalign,
|
||||
this.bytesize,
|
||||
attributes,
|
||||
documentation,
|
||||
declarationFile
|
||||
);
|
||||
}
|
||||
}
|
||||
131
tests/ts/reflection/rpccall.js
Normal file
131
tests/ts/reflection/rpccall.js
Normal file
@@ -0,0 +1,131 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
import { KeyValue } from '../reflection/key-value.js';
|
||||
import { Object_ } from '../reflection/object.js';
|
||||
export class RPCCall {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsRPCCall(bb, obj) {
|
||||
return (obj || new RPCCall()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsRPCCall(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new RPCCall()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
name(optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
request(obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? (obj || new Object_()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
|
||||
}
|
||||
response(obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
return offset ? (obj || new Object_()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
|
||||
}
|
||||
attributes(index, obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
return offset ? (obj || new KeyValue()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
||||
}
|
||||
attributesLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
documentation(index, optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
|
||||
}
|
||||
documentationLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'reflection_RPCCall';
|
||||
}
|
||||
static startRPCCall(builder) {
|
||||
builder.startObject(5);
|
||||
}
|
||||
static addName(builder, nameOffset) {
|
||||
builder.addFieldOffset(0, nameOffset, 0);
|
||||
}
|
||||
static addRequest(builder, requestOffset) {
|
||||
builder.addFieldOffset(1, requestOffset, 0);
|
||||
}
|
||||
static addResponse(builder, responseOffset) {
|
||||
builder.addFieldOffset(2, responseOffset, 0);
|
||||
}
|
||||
static addAttributes(builder, attributesOffset) {
|
||||
builder.addFieldOffset(3, attributesOffset, 0);
|
||||
}
|
||||
static createAttributesVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startAttributesVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static addDocumentation(builder, documentationOffset) {
|
||||
builder.addFieldOffset(4, documentationOffset, 0);
|
||||
}
|
||||
static createDocumentationVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startDocumentationVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static endRPCCall(builder) {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4); // name
|
||||
builder.requiredField(offset, 6); // request
|
||||
builder.requiredField(offset, 8); // response
|
||||
return offset;
|
||||
}
|
||||
unpack() {
|
||||
return new RPCCallT(this.name(), (this.request() !== null ? this.request().unpack() : null), (this.response() !== null ? this.response().unpack() : null), this.bb.createObjList(this.attributes.bind(this), this.attributesLength()), this.bb.createScalarList(this.documentation.bind(this), this.documentationLength()));
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.name = this.name();
|
||||
_o.request = (this.request() !== null ? this.request().unpack() : null);
|
||||
_o.response = (this.response() !== null ? this.response().unpack() : null);
|
||||
_o.attributes = this.bb.createObjList(this.attributes.bind(this), this.attributesLength());
|
||||
_o.documentation = this.bb.createScalarList(this.documentation.bind(this), this.documentationLength());
|
||||
}
|
||||
}
|
||||
export class RPCCallT {
|
||||
constructor(name = null, request = null, response = null, attributes = [], documentation = []) {
|
||||
this.name = name;
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
this.attributes = attributes;
|
||||
this.documentation = documentation;
|
||||
}
|
||||
pack(builder) {
|
||||
const name = (this.name !== null ? builder.createString(this.name) : 0);
|
||||
const request = (this.request !== null ? this.request.pack(builder) : 0);
|
||||
const response = (this.response !== null ? this.response.pack(builder) : 0);
|
||||
const attributes = RPCCall.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes));
|
||||
const documentation = RPCCall.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation));
|
||||
RPCCall.startRPCCall(builder);
|
||||
RPCCall.addName(builder, name);
|
||||
RPCCall.addRequest(builder, request);
|
||||
RPCCall.addResponse(builder, response);
|
||||
RPCCall.addAttributes(builder, attributes);
|
||||
RPCCall.addDocumentation(builder, documentation);
|
||||
return RPCCall.endRPCCall(builder);
|
||||
}
|
||||
}
|
||||
173
tests/ts/reflection/rpccall.ts
Normal file
173
tests/ts/reflection/rpccall.ts
Normal file
@@ -0,0 +1,173 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { KeyValue, KeyValueT } from '../reflection/key-value.js';
|
||||
import { Object_, Object_T } from '../reflection/object.js';
|
||||
|
||||
|
||||
export class RPCCall {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):RPCCall {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsRPCCall(bb:flatbuffers.ByteBuffer, obj?:RPCCall):RPCCall {
|
||||
return (obj || new RPCCall()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsRPCCall(bb:flatbuffers.ByteBuffer, obj?:RPCCall):RPCCall {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new RPCCall()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
name():string|null
|
||||
name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||
name(optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
request(obj?:Object_):Object_|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? (obj || new Object_()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
|
||||
}
|
||||
|
||||
response(obj?:Object_):Object_|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
return offset ? (obj || new Object_()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
|
||||
}
|
||||
|
||||
attributes(index: number, obj?:KeyValue):KeyValue|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
return offset ? (obj || new KeyValue()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
|
||||
}
|
||||
|
||||
attributesLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
documentation(index: number):string
|
||||
documentation(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array
|
||||
documentation(index: number,optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb!.__string(this.bb!.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
documentationLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'reflection_RPCCall';
|
||||
}
|
||||
|
||||
static startRPCCall(builder:flatbuffers.Builder) {
|
||||
builder.startObject(5);
|
||||
}
|
||||
|
||||
static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(0, nameOffset, 0);
|
||||
}
|
||||
|
||||
static addRequest(builder:flatbuffers.Builder, requestOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(1, requestOffset, 0);
|
||||
}
|
||||
|
||||
static addResponse(builder:flatbuffers.Builder, responseOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(2, responseOffset, 0);
|
||||
}
|
||||
|
||||
static addAttributes(builder:flatbuffers.Builder, attributesOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(3, attributesOffset, 0);
|
||||
}
|
||||
|
||||
static createAttributesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startAttributesVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static addDocumentation(builder:flatbuffers.Builder, documentationOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(4, documentationOffset, 0);
|
||||
}
|
||||
|
||||
static createDocumentationVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startDocumentationVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static endRPCCall(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4) // name
|
||||
builder.requiredField(offset, 6) // request
|
||||
builder.requiredField(offset, 8) // response
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
unpack(): RPCCallT {
|
||||
return new RPCCallT(
|
||||
this.name(),
|
||||
(this.request() !== null ? this.request()!.unpack() : null),
|
||||
(this.response() !== null ? this.response()!.unpack() : null),
|
||||
this.bb!.createObjList(this.attributes.bind(this), this.attributesLength()),
|
||||
this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: RPCCallT): void {
|
||||
_o.name = this.name();
|
||||
_o.request = (this.request() !== null ? this.request()!.unpack() : null);
|
||||
_o.response = (this.response() !== null ? this.response()!.unpack() : null);
|
||||
_o.attributes = this.bb!.createObjList(this.attributes.bind(this), this.attributesLength());
|
||||
_o.documentation = this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength());
|
||||
}
|
||||
}
|
||||
|
||||
export class RPCCallT {
|
||||
constructor(
|
||||
public name: string|Uint8Array|null = null,
|
||||
public request: Object_T|null = null,
|
||||
public response: Object_T|null = null,
|
||||
public attributes: (KeyValueT)[] = [],
|
||||
public documentation: (string)[] = []
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const name = (this.name !== null ? builder.createString(this.name!) : 0);
|
||||
const request = (this.request !== null ? this.request!.pack(builder) : 0);
|
||||
const response = (this.response !== null ? this.response!.pack(builder) : 0);
|
||||
const attributes = RPCCall.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes));
|
||||
const documentation = RPCCall.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation));
|
||||
|
||||
RPCCall.startRPCCall(builder);
|
||||
RPCCall.addName(builder, name);
|
||||
RPCCall.addRequest(builder, request);
|
||||
RPCCall.addResponse(builder, response);
|
||||
RPCCall.addAttributes(builder, attributes);
|
||||
RPCCall.addDocumentation(builder, documentation);
|
||||
|
||||
return RPCCall.endRPCCall(builder);
|
||||
}
|
||||
}
|
||||
88
tests/ts/reflection/schema-file.js
Normal file
88
tests/ts/reflection/schema-file.js
Normal file
@@ -0,0 +1,88 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
/**
|
||||
* File specific information.
|
||||
* Symbols declared within a file may be recovered by iterating over all
|
||||
* symbols and examining the `declaration_file` field.
|
||||
*/
|
||||
export class SchemaFile {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsSchemaFile(bb, obj) {
|
||||
return (obj || new SchemaFile()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsSchemaFile(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new SchemaFile()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
filename(optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
includedFilenames(index, optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
|
||||
}
|
||||
includedFilenamesLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'reflection_SchemaFile';
|
||||
}
|
||||
static startSchemaFile(builder) {
|
||||
builder.startObject(2);
|
||||
}
|
||||
static addFilename(builder, filenameOffset) {
|
||||
builder.addFieldOffset(0, filenameOffset, 0);
|
||||
}
|
||||
static addIncludedFilenames(builder, includedFilenamesOffset) {
|
||||
builder.addFieldOffset(1, includedFilenamesOffset, 0);
|
||||
}
|
||||
static createIncludedFilenamesVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startIncludedFilenamesVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static endSchemaFile(builder) {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4); // filename
|
||||
return offset;
|
||||
}
|
||||
static createSchemaFile(builder, filenameOffset, includedFilenamesOffset) {
|
||||
SchemaFile.startSchemaFile(builder);
|
||||
SchemaFile.addFilename(builder, filenameOffset);
|
||||
SchemaFile.addIncludedFilenames(builder, includedFilenamesOffset);
|
||||
return SchemaFile.endSchemaFile(builder);
|
||||
}
|
||||
unpack() {
|
||||
return new SchemaFileT(this.filename(), this.bb.createScalarList(this.includedFilenames.bind(this), this.includedFilenamesLength()));
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.filename = this.filename();
|
||||
_o.includedFilenames = this.bb.createScalarList(this.includedFilenames.bind(this), this.includedFilenamesLength());
|
||||
}
|
||||
}
|
||||
export class SchemaFileT {
|
||||
constructor(filename = null, includedFilenames = []) {
|
||||
this.filename = filename;
|
||||
this.includedFilenames = includedFilenames;
|
||||
}
|
||||
pack(builder) {
|
||||
const filename = (this.filename !== null ? builder.createString(this.filename) : 0);
|
||||
const includedFilenames = SchemaFile.createIncludedFilenamesVector(builder, builder.createObjectOffsetList(this.includedFilenames));
|
||||
return SchemaFile.createSchemaFile(builder, filename, includedFilenames);
|
||||
}
|
||||
}
|
||||
126
tests/ts/reflection/schema-file.ts
Normal file
126
tests/ts/reflection/schema-file.ts
Normal file
@@ -0,0 +1,126 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* File specific information.
|
||||
* Symbols declared within a file may be recovered by iterating over all
|
||||
* symbols and examining the `declaration_file` field.
|
||||
*/
|
||||
export class SchemaFile {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):SchemaFile {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsSchemaFile(bb:flatbuffers.ByteBuffer, obj?:SchemaFile):SchemaFile {
|
||||
return (obj || new SchemaFile()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsSchemaFile(bb:flatbuffers.ByteBuffer, obj?:SchemaFile):SchemaFile {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new SchemaFile()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filename, relative to project root.
|
||||
*/
|
||||
filename():string|null
|
||||
filename(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||
filename(optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Names of included files, relative to project root.
|
||||
*/
|
||||
includedFilenames(index: number):string
|
||||
includedFilenames(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array
|
||||
includedFilenames(index: number,optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.__string(this.bb!.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
includedFilenamesLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'reflection_SchemaFile';
|
||||
}
|
||||
|
||||
static startSchemaFile(builder:flatbuffers.Builder) {
|
||||
builder.startObject(2);
|
||||
}
|
||||
|
||||
static addFilename(builder:flatbuffers.Builder, filenameOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(0, filenameOffset, 0);
|
||||
}
|
||||
|
||||
static addIncludedFilenames(builder:flatbuffers.Builder, includedFilenamesOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(1, includedFilenamesOffset, 0);
|
||||
}
|
||||
|
||||
static createIncludedFilenamesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startIncludedFilenamesVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static endSchemaFile(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4) // filename
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createSchemaFile(builder:flatbuffers.Builder, filenameOffset:flatbuffers.Offset, includedFilenamesOffset:flatbuffers.Offset):flatbuffers.Offset {
|
||||
SchemaFile.startSchemaFile(builder);
|
||||
SchemaFile.addFilename(builder, filenameOffset);
|
||||
SchemaFile.addIncludedFilenames(builder, includedFilenamesOffset);
|
||||
return SchemaFile.endSchemaFile(builder);
|
||||
}
|
||||
|
||||
unpack(): SchemaFileT {
|
||||
return new SchemaFileT(
|
||||
this.filename(),
|
||||
this.bb!.createScalarList(this.includedFilenames.bind(this), this.includedFilenamesLength())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: SchemaFileT): void {
|
||||
_o.filename = this.filename();
|
||||
_o.includedFilenames = this.bb!.createScalarList(this.includedFilenames.bind(this), this.includedFilenamesLength());
|
||||
}
|
||||
}
|
||||
|
||||
export class SchemaFileT {
|
||||
constructor(
|
||||
public filename: string|Uint8Array|null = null,
|
||||
public includedFilenames: (string)[] = []
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const filename = (this.filename !== null ? builder.createString(this.filename!) : 0);
|
||||
const includedFilenames = SchemaFile.createIncludedFilenamesVector(builder, builder.createObjectOffsetList(this.includedFilenames));
|
||||
|
||||
return SchemaFile.createSchemaFile(builder,
|
||||
filename,
|
||||
includedFilenames
|
||||
);
|
||||
}
|
||||
}
|
||||
213
tests/ts/reflection/schema.js
Normal file
213
tests/ts/reflection/schema.js
Normal file
@@ -0,0 +1,213 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
import { Enum } from '../reflection/enum.js';
|
||||
import { Object_ } from '../reflection/object.js';
|
||||
import { SchemaFile } from '../reflection/schema-file.js';
|
||||
import { Service } from '../reflection/service.js';
|
||||
export class Schema {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsSchema(bb, obj) {
|
||||
return (obj || new Schema()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsSchema(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Schema()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static bufferHasIdentifier(bb) {
|
||||
return bb.__has_identifier('BFBS');
|
||||
}
|
||||
objects(index, obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? (obj || new Object_()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
||||
}
|
||||
objectsLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
enums(index, obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? (obj || new Enum()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
||||
}
|
||||
enumsLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
fileIdent(optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
fileExt(optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
rootTable(obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
return offset ? (obj || new Object_()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
|
||||
}
|
||||
services(index, obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
return offset ? (obj || new Service()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
||||
}
|
||||
servicesLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
advancedFeatures() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 16);
|
||||
return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
mutate_advanced_features(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 16);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeUint64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* All the files used in this compilation. Files are relative to where
|
||||
* flatc was invoked.
|
||||
*/
|
||||
fbsFiles(index, obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 18);
|
||||
return offset ? (obj || new SchemaFile()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
||||
}
|
||||
fbsFilesLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 18);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'reflection_Schema';
|
||||
}
|
||||
static startSchema(builder) {
|
||||
builder.startObject(8);
|
||||
}
|
||||
static addObjects(builder, objectsOffset) {
|
||||
builder.addFieldOffset(0, objectsOffset, 0);
|
||||
}
|
||||
static createObjectsVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startObjectsVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static addEnums(builder, enumsOffset) {
|
||||
builder.addFieldOffset(1, enumsOffset, 0);
|
||||
}
|
||||
static createEnumsVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startEnumsVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static addFileIdent(builder, fileIdentOffset) {
|
||||
builder.addFieldOffset(2, fileIdentOffset, 0);
|
||||
}
|
||||
static addFileExt(builder, fileExtOffset) {
|
||||
builder.addFieldOffset(3, fileExtOffset, 0);
|
||||
}
|
||||
static addRootTable(builder, rootTableOffset) {
|
||||
builder.addFieldOffset(4, rootTableOffset, 0);
|
||||
}
|
||||
static addServices(builder, servicesOffset) {
|
||||
builder.addFieldOffset(5, servicesOffset, 0);
|
||||
}
|
||||
static createServicesVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startServicesVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static addAdvancedFeatures(builder, advancedFeatures) {
|
||||
builder.addFieldInt64(6, advancedFeatures, BigInt('0'));
|
||||
}
|
||||
static addFbsFiles(builder, fbsFilesOffset) {
|
||||
builder.addFieldOffset(7, fbsFilesOffset, 0);
|
||||
}
|
||||
static createFbsFilesVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startFbsFilesVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static endSchema(builder) {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4); // objects
|
||||
builder.requiredField(offset, 6); // enums
|
||||
return offset;
|
||||
}
|
||||
static finishSchemaBuffer(builder, offset) {
|
||||
builder.finish(offset, 'BFBS');
|
||||
}
|
||||
static finishSizePrefixedSchemaBuffer(builder, offset) {
|
||||
builder.finish(offset, 'BFBS', true);
|
||||
}
|
||||
unpack() {
|
||||
return new SchemaT(this.bb.createObjList(this.objects.bind(this), this.objectsLength()), this.bb.createObjList(this.enums.bind(this), this.enumsLength()), this.fileIdent(), this.fileExt(), (this.rootTable() !== null ? this.rootTable().unpack() : null), this.bb.createObjList(this.services.bind(this), this.servicesLength()), this.advancedFeatures(), this.bb.createObjList(this.fbsFiles.bind(this), this.fbsFilesLength()));
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.objects = this.bb.createObjList(this.objects.bind(this), this.objectsLength());
|
||||
_o.enums = this.bb.createObjList(this.enums.bind(this), this.enumsLength());
|
||||
_o.fileIdent = this.fileIdent();
|
||||
_o.fileExt = this.fileExt();
|
||||
_o.rootTable = (this.rootTable() !== null ? this.rootTable().unpack() : null);
|
||||
_o.services = this.bb.createObjList(this.services.bind(this), this.servicesLength());
|
||||
_o.advancedFeatures = this.advancedFeatures();
|
||||
_o.fbsFiles = this.bb.createObjList(this.fbsFiles.bind(this), this.fbsFilesLength());
|
||||
}
|
||||
}
|
||||
export class SchemaT {
|
||||
constructor(objects = [], enums = [], fileIdent = null, fileExt = null, rootTable = null, services = [], advancedFeatures = BigInt('0'), fbsFiles = []) {
|
||||
this.objects = objects;
|
||||
this.enums = enums;
|
||||
this.fileIdent = fileIdent;
|
||||
this.fileExt = fileExt;
|
||||
this.rootTable = rootTable;
|
||||
this.services = services;
|
||||
this.advancedFeatures = advancedFeatures;
|
||||
this.fbsFiles = fbsFiles;
|
||||
}
|
||||
pack(builder) {
|
||||
const objects = Schema.createObjectsVector(builder, builder.createObjectOffsetList(this.objects));
|
||||
const enums = Schema.createEnumsVector(builder, builder.createObjectOffsetList(this.enums));
|
||||
const fileIdent = (this.fileIdent !== null ? builder.createString(this.fileIdent) : 0);
|
||||
const fileExt = (this.fileExt !== null ? builder.createString(this.fileExt) : 0);
|
||||
const rootTable = (this.rootTable !== null ? this.rootTable.pack(builder) : 0);
|
||||
const services = Schema.createServicesVector(builder, builder.createObjectOffsetList(this.services));
|
||||
const fbsFiles = Schema.createFbsFilesVector(builder, builder.createObjectOffsetList(this.fbsFiles));
|
||||
Schema.startSchema(builder);
|
||||
Schema.addObjects(builder, objects);
|
||||
Schema.addEnums(builder, enums);
|
||||
Schema.addFileIdent(builder, fileIdent);
|
||||
Schema.addFileExt(builder, fileExt);
|
||||
Schema.addRootTable(builder, rootTable);
|
||||
Schema.addServices(builder, services);
|
||||
Schema.addAdvancedFeatures(builder, this.advancedFeatures);
|
||||
Schema.addFbsFiles(builder, fbsFiles);
|
||||
return Schema.endSchema(builder);
|
||||
}
|
||||
}
|
||||
276
tests/ts/reflection/schema.ts
Normal file
276
tests/ts/reflection/schema.ts
Normal file
@@ -0,0 +1,276 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { Enum, EnumT } from '../reflection/enum.js';
|
||||
import { Object_, Object_T } from '../reflection/object.js';
|
||||
import { SchemaFile, SchemaFileT } from '../reflection/schema-file.js';
|
||||
import { Service, ServiceT } from '../reflection/service.js';
|
||||
|
||||
|
||||
export class Schema {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Schema {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsSchema(bb:flatbuffers.ByteBuffer, obj?:Schema):Schema {
|
||||
return (obj || new Schema()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsSchema(bb:flatbuffers.ByteBuffer, obj?:Schema):Schema {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Schema()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static bufferHasIdentifier(bb:flatbuffers.ByteBuffer):boolean {
|
||||
return bb.__has_identifier('BFBS');
|
||||
}
|
||||
|
||||
objects(index: number, obj?:Object_):Object_|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? (obj || new Object_()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
|
||||
}
|
||||
|
||||
objectsLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
enums(index: number, obj?:Enum):Enum|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? (obj || new Enum()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
|
||||
}
|
||||
|
||||
enumsLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
fileIdent():string|null
|
||||
fileIdent(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||
fileIdent(optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
fileExt():string|null
|
||||
fileExt(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||
fileExt(optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
rootTable(obj?:Object_):Object_|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? (obj || new Object_()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
|
||||
}
|
||||
|
||||
services(index: number, obj?:Service):Service|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
return offset ? (obj || new Service()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
|
||||
}
|
||||
|
||||
servicesLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
advancedFeatures():bigint {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 16);
|
||||
return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
|
||||
mutate_advanced_features(value:bigint):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 16);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeUint64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* All the files used in this compilation. Files are relative to where
|
||||
* flatc was invoked.
|
||||
*/
|
||||
fbsFiles(index: number, obj?:SchemaFile):SchemaFile|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 18);
|
||||
return offset ? (obj || new SchemaFile()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
|
||||
}
|
||||
|
||||
fbsFilesLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 18);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'reflection_Schema';
|
||||
}
|
||||
|
||||
static startSchema(builder:flatbuffers.Builder) {
|
||||
builder.startObject(8);
|
||||
}
|
||||
|
||||
static addObjects(builder:flatbuffers.Builder, objectsOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(0, objectsOffset, 0);
|
||||
}
|
||||
|
||||
static createObjectsVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startObjectsVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static addEnums(builder:flatbuffers.Builder, enumsOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(1, enumsOffset, 0);
|
||||
}
|
||||
|
||||
static createEnumsVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startEnumsVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static addFileIdent(builder:flatbuffers.Builder, fileIdentOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(2, fileIdentOffset, 0);
|
||||
}
|
||||
|
||||
static addFileExt(builder:flatbuffers.Builder, fileExtOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(3, fileExtOffset, 0);
|
||||
}
|
||||
|
||||
static addRootTable(builder:flatbuffers.Builder, rootTableOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(4, rootTableOffset, 0);
|
||||
}
|
||||
|
||||
static addServices(builder:flatbuffers.Builder, servicesOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(5, servicesOffset, 0);
|
||||
}
|
||||
|
||||
static createServicesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startServicesVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static addAdvancedFeatures(builder:flatbuffers.Builder, advancedFeatures:bigint) {
|
||||
builder.addFieldInt64(6, advancedFeatures, BigInt('0'));
|
||||
}
|
||||
|
||||
static addFbsFiles(builder:flatbuffers.Builder, fbsFilesOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(7, fbsFilesOffset, 0);
|
||||
}
|
||||
|
||||
static createFbsFilesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startFbsFilesVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static endSchema(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4) // objects
|
||||
builder.requiredField(offset, 6) // enums
|
||||
return offset;
|
||||
}
|
||||
|
||||
static finishSchemaBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) {
|
||||
builder.finish(offset, 'BFBS');
|
||||
}
|
||||
|
||||
static finishSizePrefixedSchemaBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) {
|
||||
builder.finish(offset, 'BFBS', true);
|
||||
}
|
||||
|
||||
|
||||
unpack(): SchemaT {
|
||||
return new SchemaT(
|
||||
this.bb!.createObjList(this.objects.bind(this), this.objectsLength()),
|
||||
this.bb!.createObjList(this.enums.bind(this), this.enumsLength()),
|
||||
this.fileIdent(),
|
||||
this.fileExt(),
|
||||
(this.rootTable() !== null ? this.rootTable()!.unpack() : null),
|
||||
this.bb!.createObjList(this.services.bind(this), this.servicesLength()),
|
||||
this.advancedFeatures(),
|
||||
this.bb!.createObjList(this.fbsFiles.bind(this), this.fbsFilesLength())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: SchemaT): void {
|
||||
_o.objects = this.bb!.createObjList(this.objects.bind(this), this.objectsLength());
|
||||
_o.enums = this.bb!.createObjList(this.enums.bind(this), this.enumsLength());
|
||||
_o.fileIdent = this.fileIdent();
|
||||
_o.fileExt = this.fileExt();
|
||||
_o.rootTable = (this.rootTable() !== null ? this.rootTable()!.unpack() : null);
|
||||
_o.services = this.bb!.createObjList(this.services.bind(this), this.servicesLength());
|
||||
_o.advancedFeatures = this.advancedFeatures();
|
||||
_o.fbsFiles = this.bb!.createObjList(this.fbsFiles.bind(this), this.fbsFilesLength());
|
||||
}
|
||||
}
|
||||
|
||||
export class SchemaT {
|
||||
constructor(
|
||||
public objects: (Object_T)[] = [],
|
||||
public enums: (EnumT)[] = [],
|
||||
public fileIdent: string|Uint8Array|null = null,
|
||||
public fileExt: string|Uint8Array|null = null,
|
||||
public rootTable: Object_T|null = null,
|
||||
public services: (ServiceT)[] = [],
|
||||
public advancedFeatures: bigint = BigInt('0'),
|
||||
public fbsFiles: (SchemaFileT)[] = []
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const objects = Schema.createObjectsVector(builder, builder.createObjectOffsetList(this.objects));
|
||||
const enums = Schema.createEnumsVector(builder, builder.createObjectOffsetList(this.enums));
|
||||
const fileIdent = (this.fileIdent !== null ? builder.createString(this.fileIdent!) : 0);
|
||||
const fileExt = (this.fileExt !== null ? builder.createString(this.fileExt!) : 0);
|
||||
const rootTable = (this.rootTable !== null ? this.rootTable!.pack(builder) : 0);
|
||||
const services = Schema.createServicesVector(builder, builder.createObjectOffsetList(this.services));
|
||||
const fbsFiles = Schema.createFbsFilesVector(builder, builder.createObjectOffsetList(this.fbsFiles));
|
||||
|
||||
Schema.startSchema(builder);
|
||||
Schema.addObjects(builder, objects);
|
||||
Schema.addEnums(builder, enums);
|
||||
Schema.addFileIdent(builder, fileIdent);
|
||||
Schema.addFileExt(builder, fileExt);
|
||||
Schema.addRootTable(builder, rootTable);
|
||||
Schema.addServices(builder, services);
|
||||
Schema.addAdvancedFeatures(builder, this.advancedFeatures);
|
||||
Schema.addFbsFiles(builder, fbsFiles);
|
||||
|
||||
return Schema.endSchema(builder);
|
||||
}
|
||||
}
|
||||
146
tests/ts/reflection/service.js
Normal file
146
tests/ts/reflection/service.js
Normal file
@@ -0,0 +1,146 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
import { KeyValue } from '../reflection/key-value.js';
|
||||
import { RPCCall } from '../reflection/rpccall.js';
|
||||
export class Service {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsService(bb, obj) {
|
||||
return (obj || new Service()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsService(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Service()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
name(optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
calls(index, obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? (obj || new RPCCall()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
||||
}
|
||||
callsLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
attributes(index, obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
return offset ? (obj || new KeyValue()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
||||
}
|
||||
attributesLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
documentation(index, optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
|
||||
}
|
||||
documentationLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
declarationFile(optionalEncoding) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'reflection_Service';
|
||||
}
|
||||
static startService(builder) {
|
||||
builder.startObject(5);
|
||||
}
|
||||
static addName(builder, nameOffset) {
|
||||
builder.addFieldOffset(0, nameOffset, 0);
|
||||
}
|
||||
static addCalls(builder, callsOffset) {
|
||||
builder.addFieldOffset(1, callsOffset, 0);
|
||||
}
|
||||
static createCallsVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startCallsVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static addAttributes(builder, attributesOffset) {
|
||||
builder.addFieldOffset(2, attributesOffset, 0);
|
||||
}
|
||||
static createAttributesVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startAttributesVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static addDocumentation(builder, documentationOffset) {
|
||||
builder.addFieldOffset(3, documentationOffset, 0);
|
||||
}
|
||||
static createDocumentationVector(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
static startDocumentationVector(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
static addDeclarationFile(builder, declarationFileOffset) {
|
||||
builder.addFieldOffset(4, declarationFileOffset, 0);
|
||||
}
|
||||
static endService(builder) {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4); // name
|
||||
return offset;
|
||||
}
|
||||
static createService(builder, nameOffset, callsOffset, attributesOffset, documentationOffset, declarationFileOffset) {
|
||||
Service.startService(builder);
|
||||
Service.addName(builder, nameOffset);
|
||||
Service.addCalls(builder, callsOffset);
|
||||
Service.addAttributes(builder, attributesOffset);
|
||||
Service.addDocumentation(builder, documentationOffset);
|
||||
Service.addDeclarationFile(builder, declarationFileOffset);
|
||||
return Service.endService(builder);
|
||||
}
|
||||
unpack() {
|
||||
return new ServiceT(this.name(), this.bb.createObjList(this.calls.bind(this), this.callsLength()), this.bb.createObjList(this.attributes.bind(this), this.attributesLength()), this.bb.createScalarList(this.documentation.bind(this), this.documentationLength()), this.declarationFile());
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.name = this.name();
|
||||
_o.calls = this.bb.createObjList(this.calls.bind(this), this.callsLength());
|
||||
_o.attributes = this.bb.createObjList(this.attributes.bind(this), this.attributesLength());
|
||||
_o.documentation = this.bb.createScalarList(this.documentation.bind(this), this.documentationLength());
|
||||
_o.declarationFile = this.declarationFile();
|
||||
}
|
||||
}
|
||||
export class ServiceT {
|
||||
constructor(name = null, calls = [], attributes = [], documentation = [], declarationFile = null) {
|
||||
this.name = name;
|
||||
this.calls = calls;
|
||||
this.attributes = attributes;
|
||||
this.documentation = documentation;
|
||||
this.declarationFile = declarationFile;
|
||||
}
|
||||
pack(builder) {
|
||||
const name = (this.name !== null ? builder.createString(this.name) : 0);
|
||||
const calls = Service.createCallsVector(builder, builder.createObjectOffsetList(this.calls));
|
||||
const attributes = Service.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes));
|
||||
const documentation = Service.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation));
|
||||
const declarationFile = (this.declarationFile !== null ? builder.createString(this.declarationFile) : 0);
|
||||
return Service.createService(builder, name, calls, attributes, documentation, declarationFile);
|
||||
}
|
||||
}
|
||||
201
tests/ts/reflection/service.ts
Normal file
201
tests/ts/reflection/service.ts
Normal file
@@ -0,0 +1,201 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { KeyValue, KeyValueT } from '../reflection/key-value.js';
|
||||
import { RPCCall, RPCCallT } from '../reflection/rpccall.js';
|
||||
|
||||
|
||||
export class Service {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Service {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsService(bb:flatbuffers.ByteBuffer, obj?:Service):Service {
|
||||
return (obj || new Service()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsService(bb:flatbuffers.ByteBuffer, obj?:Service):Service {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Service()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
name():string|null
|
||||
name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||
name(optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
calls(index: number, obj?:RPCCall):RPCCall|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? (obj || new RPCCall()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
|
||||
}
|
||||
|
||||
callsLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
attributes(index: number, obj?:KeyValue):KeyValue|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
return offset ? (obj || new KeyValue()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
|
||||
}
|
||||
|
||||
attributesLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
documentation(index: number):string
|
||||
documentation(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array
|
||||
documentation(index: number,optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb!.__string(this.bb!.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
documentationLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* File that this Service is declared in.
|
||||
*/
|
||||
declarationFile():string|null
|
||||
declarationFile(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||
declarationFile(optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'reflection_Service';
|
||||
}
|
||||
|
||||
static startService(builder:flatbuffers.Builder) {
|
||||
builder.startObject(5);
|
||||
}
|
||||
|
||||
static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(0, nameOffset, 0);
|
||||
}
|
||||
|
||||
static addCalls(builder:flatbuffers.Builder, callsOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(1, callsOffset, 0);
|
||||
}
|
||||
|
||||
static createCallsVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startCallsVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static addAttributes(builder:flatbuffers.Builder, attributesOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(2, attributesOffset, 0);
|
||||
}
|
||||
|
||||
static createAttributesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startAttributesVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static addDocumentation(builder:flatbuffers.Builder, documentationOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(3, documentationOffset, 0);
|
||||
}
|
||||
|
||||
static createDocumentationVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startDocumentationVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static addDeclarationFile(builder:flatbuffers.Builder, declarationFileOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(4, declarationFileOffset, 0);
|
||||
}
|
||||
|
||||
static endService(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4) // name
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createService(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset, callsOffset:flatbuffers.Offset, attributesOffset:flatbuffers.Offset, documentationOffset:flatbuffers.Offset, declarationFileOffset:flatbuffers.Offset):flatbuffers.Offset {
|
||||
Service.startService(builder);
|
||||
Service.addName(builder, nameOffset);
|
||||
Service.addCalls(builder, callsOffset);
|
||||
Service.addAttributes(builder, attributesOffset);
|
||||
Service.addDocumentation(builder, documentationOffset);
|
||||
Service.addDeclarationFile(builder, declarationFileOffset);
|
||||
return Service.endService(builder);
|
||||
}
|
||||
|
||||
unpack(): ServiceT {
|
||||
return new ServiceT(
|
||||
this.name(),
|
||||
this.bb!.createObjList(this.calls.bind(this), this.callsLength()),
|
||||
this.bb!.createObjList(this.attributes.bind(this), this.attributesLength()),
|
||||
this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength()),
|
||||
this.declarationFile()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: ServiceT): void {
|
||||
_o.name = this.name();
|
||||
_o.calls = this.bb!.createObjList(this.calls.bind(this), this.callsLength());
|
||||
_o.attributes = this.bb!.createObjList(this.attributes.bind(this), this.attributesLength());
|
||||
_o.documentation = this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength());
|
||||
_o.declarationFile = this.declarationFile();
|
||||
}
|
||||
}
|
||||
|
||||
export class ServiceT {
|
||||
constructor(
|
||||
public name: string|Uint8Array|null = null,
|
||||
public calls: (RPCCallT)[] = [],
|
||||
public attributes: (KeyValueT)[] = [],
|
||||
public documentation: (string)[] = [],
|
||||
public declarationFile: string|Uint8Array|null = null
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const name = (this.name !== null ? builder.createString(this.name!) : 0);
|
||||
const calls = Service.createCallsVector(builder, builder.createObjectOffsetList(this.calls));
|
||||
const attributes = Service.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes));
|
||||
const documentation = Service.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation));
|
||||
const declarationFile = (this.declarationFile !== null ? builder.createString(this.declarationFile!) : 0);
|
||||
|
||||
return Service.createService(builder,
|
||||
name,
|
||||
calls,
|
||||
attributes,
|
||||
documentation,
|
||||
declarationFile
|
||||
);
|
||||
}
|
||||
}
|
||||
161
tests/ts/reflection/type.js
Normal file
161
tests/ts/reflection/type.js
Normal file
@@ -0,0 +1,161 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
import { BaseType } from '../reflection/base-type.js';
|
||||
export class Type {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsType(bb, obj) {
|
||||
return (obj || new Type()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsType(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Type()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
baseType() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.readInt8(this.bb_pos + offset) : BaseType.None;
|
||||
}
|
||||
mutate_base_type(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt8(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
element() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb.readInt8(this.bb_pos + offset) : BaseType.None;
|
||||
}
|
||||
mutate_element(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt8(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
index() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : -1;
|
||||
}
|
||||
mutate_index(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
fixedLength() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb.readUint16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_fixed_length(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeUint16(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* The size (octets) of the `base_type` field.
|
||||
*/
|
||||
baseSize() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb.readUint32(this.bb_pos + offset) : 4;
|
||||
}
|
||||
mutate_base_size(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeUint32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* The size (octets) of the `element` field, if present.
|
||||
*/
|
||||
elementSize() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb.readUint32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_element_size(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeUint32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'reflection_Type';
|
||||
}
|
||||
static startType(builder) {
|
||||
builder.startObject(6);
|
||||
}
|
||||
static addBaseType(builder, baseType) {
|
||||
builder.addFieldInt8(0, baseType, BaseType.None);
|
||||
}
|
||||
static addElement(builder, element) {
|
||||
builder.addFieldInt8(1, element, BaseType.None);
|
||||
}
|
||||
static addIndex(builder, index) {
|
||||
builder.addFieldInt32(2, index, -1);
|
||||
}
|
||||
static addFixedLength(builder, fixedLength) {
|
||||
builder.addFieldInt16(3, fixedLength, 0);
|
||||
}
|
||||
static addBaseSize(builder, baseSize) {
|
||||
builder.addFieldInt32(4, baseSize, 4);
|
||||
}
|
||||
static addElementSize(builder, elementSize) {
|
||||
builder.addFieldInt32(5, elementSize, 0);
|
||||
}
|
||||
static endType(builder) {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
static createType(builder, baseType, element, index, fixedLength, baseSize, elementSize) {
|
||||
Type.startType(builder);
|
||||
Type.addBaseType(builder, baseType);
|
||||
Type.addElement(builder, element);
|
||||
Type.addIndex(builder, index);
|
||||
Type.addFixedLength(builder, fixedLength);
|
||||
Type.addBaseSize(builder, baseSize);
|
||||
Type.addElementSize(builder, elementSize);
|
||||
return Type.endType(builder);
|
||||
}
|
||||
unpack() {
|
||||
return new TypeT(this.baseType(), this.element(), this.index(), this.fixedLength(), this.baseSize(), this.elementSize());
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.baseType = this.baseType();
|
||||
_o.element = this.element();
|
||||
_o.index = this.index();
|
||||
_o.fixedLength = this.fixedLength();
|
||||
_o.baseSize = this.baseSize();
|
||||
_o.elementSize = this.elementSize();
|
||||
}
|
||||
}
|
||||
export class TypeT {
|
||||
constructor(baseType = BaseType.None, element = BaseType.None, index = -1, fixedLength = 0, baseSize = 4, elementSize = 0) {
|
||||
this.baseType = baseType;
|
||||
this.element = element;
|
||||
this.index = index;
|
||||
this.fixedLength = fixedLength;
|
||||
this.baseSize = baseSize;
|
||||
this.elementSize = elementSize;
|
||||
}
|
||||
pack(builder) {
|
||||
return Type.createType(builder, this.baseType, this.element, this.index, this.fixedLength, this.baseSize, this.elementSize);
|
||||
}
|
||||
}
|
||||
219
tests/ts/reflection/type.ts
Normal file
219
tests/ts/reflection/type.ts
Normal file
@@ -0,0 +1,219 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { BaseType } from '../reflection/base-type.js';
|
||||
|
||||
|
||||
export class Type {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Type {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsType(bb:flatbuffers.ByteBuffer, obj?:Type):Type {
|
||||
return (obj || new Type()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsType(bb:flatbuffers.ByteBuffer, obj?:Type):Type {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Type()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
baseType():BaseType {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.readInt8(this.bb_pos + offset) : BaseType.None;
|
||||
}
|
||||
|
||||
mutate_base_type(value:BaseType):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt8(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
element():BaseType {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.readInt8(this.bb_pos + offset) : BaseType.None;
|
||||
}
|
||||
|
||||
mutate_element(value:BaseType):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt8(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
index():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : -1;
|
||||
}
|
||||
|
||||
mutate_index(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
fixedLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_fixed_length(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeUint16(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The size (octets) of the `base_type` field.
|
||||
*/
|
||||
baseSize():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb!.readUint32(this.bb_pos + offset) : 4;
|
||||
}
|
||||
|
||||
mutate_base_size(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeUint32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The size (octets) of the `element` field, if present.
|
||||
*/
|
||||
elementSize():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb!.readUint32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_element_size(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeUint32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'reflection_Type';
|
||||
}
|
||||
|
||||
static startType(builder:flatbuffers.Builder) {
|
||||
builder.startObject(6);
|
||||
}
|
||||
|
||||
static addBaseType(builder:flatbuffers.Builder, baseType:BaseType) {
|
||||
builder.addFieldInt8(0, baseType, BaseType.None);
|
||||
}
|
||||
|
||||
static addElement(builder:flatbuffers.Builder, element:BaseType) {
|
||||
builder.addFieldInt8(1, element, BaseType.None);
|
||||
}
|
||||
|
||||
static addIndex(builder:flatbuffers.Builder, index:number) {
|
||||
builder.addFieldInt32(2, index, -1);
|
||||
}
|
||||
|
||||
static addFixedLength(builder:flatbuffers.Builder, fixedLength:number) {
|
||||
builder.addFieldInt16(3, fixedLength, 0);
|
||||
}
|
||||
|
||||
static addBaseSize(builder:flatbuffers.Builder, baseSize:number) {
|
||||
builder.addFieldInt32(4, baseSize, 4);
|
||||
}
|
||||
|
||||
static addElementSize(builder:flatbuffers.Builder, elementSize:number) {
|
||||
builder.addFieldInt32(5, elementSize, 0);
|
||||
}
|
||||
|
||||
static endType(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createType(builder:flatbuffers.Builder, baseType:BaseType, element:BaseType, index:number, fixedLength:number, baseSize:number, elementSize:number):flatbuffers.Offset {
|
||||
Type.startType(builder);
|
||||
Type.addBaseType(builder, baseType);
|
||||
Type.addElement(builder, element);
|
||||
Type.addIndex(builder, index);
|
||||
Type.addFixedLength(builder, fixedLength);
|
||||
Type.addBaseSize(builder, baseSize);
|
||||
Type.addElementSize(builder, elementSize);
|
||||
return Type.endType(builder);
|
||||
}
|
||||
|
||||
unpack(): TypeT {
|
||||
return new TypeT(
|
||||
this.baseType(),
|
||||
this.element(),
|
||||
this.index(),
|
||||
this.fixedLength(),
|
||||
this.baseSize(),
|
||||
this.elementSize()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: TypeT): void {
|
||||
_o.baseType = this.baseType();
|
||||
_o.element = this.element();
|
||||
_o.index = this.index();
|
||||
_o.fixedLength = this.fixedLength();
|
||||
_o.baseSize = this.baseSize();
|
||||
_o.elementSize = this.elementSize();
|
||||
}
|
||||
}
|
||||
|
||||
export class TypeT {
|
||||
constructor(
|
||||
public baseType: BaseType = BaseType.None,
|
||||
public element: BaseType = BaseType.None,
|
||||
public index: number = -1,
|
||||
public fixedLength: number = 0,
|
||||
public baseSize: number = 4,
|
||||
public elementSize: number = 0
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return Type.createType(builder,
|
||||
this.baseType,
|
||||
this.element,
|
||||
this.index,
|
||||
this.fixedLength,
|
||||
this.baseSize,
|
||||
this.elementSize
|
||||
);
|
||||
}
|
||||
}
|
||||
1575
tests/ts/reflection_generated.js
Normal file
1575
tests/ts/reflection_generated.js
Normal file
File diff suppressed because it is too large
Load Diff
2100
tests/ts/reflection_generated.ts
Normal file
2100
tests/ts/reflection_generated.ts
Normal file
File diff suppressed because it is too large
Load Diff
14
tests/ts/test_dir/BUILD.bazel
Normal file
14
tests/ts/test_dir/BUILD.bazel
Normal file
@@ -0,0 +1,14 @@
|
||||
load("//:typescript.bzl", "flatbuffer_ts_library")
|
||||
|
||||
flatbuffer_ts_library(
|
||||
name = "typescript_transitive_ts_fbs",
|
||||
srcs = ["typescript_transitive_include.fbs"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
flatbuffer_ts_library(
|
||||
name = "include_ts_fbs",
|
||||
srcs = ["typescript_include.fbs"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [":typescript_transitive_ts_fbs"],
|
||||
)
|
||||
6
tests/ts/test_dir/typescript_include.fbs
Normal file
6
tests/ts/test_dir/typescript_include.fbs
Normal file
@@ -0,0 +1,6 @@
|
||||
include 'typescript_transitive_include.fbs';
|
||||
namespace foobar;
|
||||
|
||||
enum class: int {
|
||||
arguments,
|
||||
}
|
||||
5
tests/ts/test_dir/typescript_transitive_include.fbs
Normal file
5
tests/ts/test_dir/typescript_transitive_include.fbs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace foobar;
|
||||
|
||||
enum Abc: int {
|
||||
a,
|
||||
}
|
||||
25
tests/ts/tsconfig.json
Normal file
25
tests/ts/tsconfig.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES6",
|
||||
"lib": ["ES2015", "ES2020.BigInt", "DOM"],
|
||||
"moduleResolution": "Node",
|
||||
"noImplicitAny": true,
|
||||
"strict": true,
|
||||
"noUnusedParameters": false,
|
||||
"noUnusedLocals": false,
|
||||
"noImplicitReturns": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": ".",
|
||||
"noEmit": false
|
||||
},
|
||||
"include": [
|
||||
"monster_test.ts",
|
||||
"typescript_keywords.ts",
|
||||
"typescript_keywords_generated.ts",
|
||||
"my-game/**/*.ts",
|
||||
"typescript/**/*.ts",
|
||||
"optional_scalars/**/*.ts",
|
||||
"namespace_test/**/*.ts",
|
||||
"union_vector/**/*.ts"
|
||||
]
|
||||
}
|
||||
6
tests/ts/typescript/class.js
Normal file
6
tests/ts/typescript/class.js
Normal file
@@ -0,0 +1,6 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
export var class_;
|
||||
(function (class_) {
|
||||
class_[class_["new_"] = 0] = "new_";
|
||||
class_[class_["instanceof_"] = 1] = "instanceof_";
|
||||
})(class_ || (class_ = {}));
|
||||
6
tests/ts/typescript/class.ts
Normal file
6
tests/ts/typescript/class.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export enum class_ {
|
||||
new_ = 0,
|
||||
instanceof_ = 1
|
||||
}
|
||||
166
tests/ts/typescript/object.js
Normal file
166
tests/ts/typescript/object.js
Normal file
@@ -0,0 +1,166 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
import { Abc } from '../foobar/abc.js';
|
||||
import { class_ as foobar_class_ } from '../foobar/class.js';
|
||||
import { Schema } from '../reflection/schema.js';
|
||||
import { class_ } from '../typescript/class.js';
|
||||
export class Object_ {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsObject(bb, obj) {
|
||||
return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsObject(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
return_() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_return(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
if_() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_if(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
switch_() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_switch(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
enum_() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : class_.new_;
|
||||
}
|
||||
mutate_enum(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
enum2() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : foobar_class_.arguments_;
|
||||
}
|
||||
mutate_enum2(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
enum3() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : Abc.a;
|
||||
}
|
||||
mutate_enum3(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
reflect(obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 16);
|
||||
return offset ? (obj || new Schema()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'typescript_Object';
|
||||
}
|
||||
static startObject(builder) {
|
||||
builder.startObject(7);
|
||||
}
|
||||
static addReturn(builder, return_) {
|
||||
builder.addFieldInt32(0, return_, 0);
|
||||
}
|
||||
static addIf(builder, if_) {
|
||||
builder.addFieldInt32(1, if_, 0);
|
||||
}
|
||||
static addSwitch(builder, switch_) {
|
||||
builder.addFieldInt32(2, switch_, 0);
|
||||
}
|
||||
static addEnum(builder, enum_) {
|
||||
builder.addFieldInt32(3, enum_, class_.new_);
|
||||
}
|
||||
static addEnum2(builder, enum2) {
|
||||
builder.addFieldInt32(4, enum2, foobar_class_.arguments_);
|
||||
}
|
||||
static addEnum3(builder, enum3) {
|
||||
builder.addFieldInt32(5, enum3, Abc.a);
|
||||
}
|
||||
static addReflect(builder, reflectOffset) {
|
||||
builder.addFieldOffset(6, reflectOffset, 0);
|
||||
}
|
||||
static endObject(builder) {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
unpack() {
|
||||
return new Object_T(this.return_(), this.if_(), this.switch_(), this.enum_(), this.enum2(), this.enum3(), (this.reflect() !== null ? this.reflect().unpack() : null));
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.return_ = this.return_();
|
||||
_o.if_ = this.if_();
|
||||
_o.switch_ = this.switch_();
|
||||
_o.enum_ = this.enum_();
|
||||
_o.enum2 = this.enum2();
|
||||
_o.enum3 = this.enum3();
|
||||
_o.reflect = (this.reflect() !== null ? this.reflect().unpack() : null);
|
||||
}
|
||||
}
|
||||
export class Object_T {
|
||||
constructor(return_ = 0, if_ = 0, switch_ = 0, enum_ = class_.new_, enum2 = foobar_class_.arguments_, enum3 = Abc.a, reflect = null) {
|
||||
this.return_ = return_;
|
||||
this.if_ = if_;
|
||||
this.switch_ = switch_;
|
||||
this.enum_ = enum_;
|
||||
this.enum2 = enum2;
|
||||
this.enum3 = enum3;
|
||||
this.reflect = reflect;
|
||||
}
|
||||
pack(builder) {
|
||||
const reflect = (this.reflect !== null ? this.reflect.pack(builder) : 0);
|
||||
Object_.startObject(builder);
|
||||
Object_.addReturn(builder, this.return_);
|
||||
Object_.addIf(builder, this.if_);
|
||||
Object_.addSwitch(builder, this.switch_);
|
||||
Object_.addEnum(builder, this.enum_);
|
||||
Object_.addEnum2(builder, this.enum2);
|
||||
Object_.addEnum3(builder, this.enum3);
|
||||
Object_.addReflect(builder, reflect);
|
||||
return Object_.endObject(builder);
|
||||
}
|
||||
}
|
||||
222
tests/ts/typescript/object.ts
Normal file
222
tests/ts/typescript/object.ts
Normal file
@@ -0,0 +1,222 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { Abc } from '../foobar/abc.js';
|
||||
import { class_ as foobar_class_ } from '../foobar/class.js';
|
||||
import { Schema, SchemaT } from '../reflection/schema.js';
|
||||
import { class_ } from '../typescript/class.js';
|
||||
|
||||
|
||||
export class Object_ {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Object_ {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsObject(bb:flatbuffers.ByteBuffer, obj?:Object_):Object_ {
|
||||
return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsObject(bb:flatbuffers.ByteBuffer, obj?:Object_):Object_ {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
return_():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_return(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
if_():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_if(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
switch_():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_switch(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
enum_():class_ {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : class_.new_;
|
||||
}
|
||||
|
||||
mutate_enum(value:class_):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
enum2():foobar_class_ {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : foobar_class_.arguments_;
|
||||
}
|
||||
|
||||
mutate_enum2(value:foobar_class_):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
enum3():Abc {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : Abc.a;
|
||||
}
|
||||
|
||||
mutate_enum3(value:Abc):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
reflect(obj?:Schema):Schema|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 16);
|
||||
return offset ? (obj || new Schema()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'typescript_Object';
|
||||
}
|
||||
|
||||
static startObject(builder:flatbuffers.Builder) {
|
||||
builder.startObject(7);
|
||||
}
|
||||
|
||||
static addReturn(builder:flatbuffers.Builder, return_:number) {
|
||||
builder.addFieldInt32(0, return_, 0);
|
||||
}
|
||||
|
||||
static addIf(builder:flatbuffers.Builder, if_:number) {
|
||||
builder.addFieldInt32(1, if_, 0);
|
||||
}
|
||||
|
||||
static addSwitch(builder:flatbuffers.Builder, switch_:number) {
|
||||
builder.addFieldInt32(2, switch_, 0);
|
||||
}
|
||||
|
||||
static addEnum(builder:flatbuffers.Builder, enum_:class_) {
|
||||
builder.addFieldInt32(3, enum_, class_.new_);
|
||||
}
|
||||
|
||||
static addEnum2(builder:flatbuffers.Builder, enum2:foobar_class_) {
|
||||
builder.addFieldInt32(4, enum2, foobar_class_.arguments_);
|
||||
}
|
||||
|
||||
static addEnum3(builder:flatbuffers.Builder, enum3:Abc) {
|
||||
builder.addFieldInt32(5, enum3, Abc.a);
|
||||
}
|
||||
|
||||
static addReflect(builder:flatbuffers.Builder, reflectOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(6, reflectOffset, 0);
|
||||
}
|
||||
|
||||
static endObject(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
unpack(): Object_T {
|
||||
return new Object_T(
|
||||
this.return_(),
|
||||
this.if_(),
|
||||
this.switch_(),
|
||||
this.enum_(),
|
||||
this.enum2(),
|
||||
this.enum3(),
|
||||
(this.reflect() !== null ? this.reflect()!.unpack() : null)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: Object_T): void {
|
||||
_o.return_ = this.return_();
|
||||
_o.if_ = this.if_();
|
||||
_o.switch_ = this.switch_();
|
||||
_o.enum_ = this.enum_();
|
||||
_o.enum2 = this.enum2();
|
||||
_o.enum3 = this.enum3();
|
||||
_o.reflect = (this.reflect() !== null ? this.reflect()!.unpack() : null);
|
||||
}
|
||||
}
|
||||
|
||||
export class Object_T {
|
||||
constructor(
|
||||
public return_: number = 0,
|
||||
public if_: number = 0,
|
||||
public switch_: number = 0,
|
||||
public enum_: class_ = class_.new_,
|
||||
public enum2: foobar_class_ = foobar_class_.arguments_,
|
||||
public enum3: Abc = Abc.a,
|
||||
public reflect: SchemaT|null = null
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const reflect = (this.reflect !== null ? this.reflect!.pack(builder) : 0);
|
||||
|
||||
Object_.startObject(builder);
|
||||
Object_.addReturn(builder, this.return_);
|
||||
Object_.addIf(builder, this.if_);
|
||||
Object_.addSwitch(builder, this.switch_);
|
||||
Object_.addEnum(builder, this.enum_);
|
||||
Object_.addEnum2(builder, this.enum2);
|
||||
Object_.addEnum3(builder, this.enum3);
|
||||
Object_.addReflect(builder, reflect);
|
||||
|
||||
return Object_.endObject(builder);
|
||||
}
|
||||
}
|
||||
5
tests/ts/typescript_include_generated.js
Normal file
5
tests/ts/typescript_include_generated.js
Normal file
@@ -0,0 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
export var class_;
|
||||
(function (class_) {
|
||||
class_[class_["arguments_"] = 0] = "arguments_";
|
||||
})(class_ || (class_ = {}));
|
||||
7
tests/ts/typescript_include_generated.ts
Normal file
7
tests/ts/typescript_include_generated.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
export enum class_ {
|
||||
arguments_ = 0
|
||||
}
|
||||
|
||||
21
tests/ts/typescript_keywords.fbs
Normal file
21
tests/ts/typescript_keywords.fbs
Normal file
@@ -0,0 +1,21 @@
|
||||
include 'test_dir/typescript_include.fbs';
|
||||
include 'reflection/reflection.fbs';
|
||||
|
||||
// This file includes a variety of keywords meant to deliberately interfere
|
||||
// with typescript keywords.
|
||||
namespace typescript;
|
||||
|
||||
enum class: int {
|
||||
new,
|
||||
instanceof,
|
||||
}
|
||||
|
||||
table Object {
|
||||
return:int;
|
||||
if:int;
|
||||
switch:int;
|
||||
enum:class;
|
||||
enum2:foobar.class;
|
||||
enum3:foobar.Abc;
|
||||
reflect:reflection.Schema;
|
||||
}
|
||||
170
tests/ts/typescript_keywords_generated.js
Normal file
170
tests/ts/typescript_keywords_generated.js
Normal file
@@ -0,0 +1,170 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
import { Schema as Schema } from './reflection_generated.js';
|
||||
import { class_ as foobar_class_ } from './typescript_include_generated.js';
|
||||
import { Abc as Abc } from './typescript_transitive_include_generated.js';
|
||||
export var class_;
|
||||
(function (class_) {
|
||||
class_[class_["new_"] = 0] = "new_";
|
||||
class_[class_["instanceof_"] = 1] = "instanceof_";
|
||||
})(class_ || (class_ = {}));
|
||||
export class Object_ {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsObject(bb, obj) {
|
||||
return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsObject(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
return_() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_return(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
if_() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_if(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
switch_() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_switch(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
enum_() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : class_.new_;
|
||||
}
|
||||
mutate_enum(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
enum2() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : foobar_class_.arguments_;
|
||||
}
|
||||
mutate_enum2(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
enum3() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : Abc.a;
|
||||
}
|
||||
mutate_enum3(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
reflect(obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 16);
|
||||
return offset ? (obj || new Schema()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'typescript_Object';
|
||||
}
|
||||
static startObject(builder) {
|
||||
builder.startObject(7);
|
||||
}
|
||||
static addReturn(builder, return_) {
|
||||
builder.addFieldInt32(0, return_, 0);
|
||||
}
|
||||
static addIf(builder, if_) {
|
||||
builder.addFieldInt32(1, if_, 0);
|
||||
}
|
||||
static addSwitch(builder, switch_) {
|
||||
builder.addFieldInt32(2, switch_, 0);
|
||||
}
|
||||
static addEnum(builder, enum_) {
|
||||
builder.addFieldInt32(3, enum_, class_.new_);
|
||||
}
|
||||
static addEnum2(builder, enum2) {
|
||||
builder.addFieldInt32(4, enum2, foobar_class_.arguments_);
|
||||
}
|
||||
static addEnum3(builder, enum3) {
|
||||
builder.addFieldInt32(5, enum3, Abc.a);
|
||||
}
|
||||
static addReflect(builder, reflectOffset) {
|
||||
builder.addFieldOffset(6, reflectOffset, 0);
|
||||
}
|
||||
static endObject(builder) {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
unpack() {
|
||||
return new Object_T(this.return_(), this.if_(), this.switch_(), this.enum_(), this.enum2(), this.enum3(), (this.reflect() !== null ? this.reflect().unpack() : null));
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.return_ = this.return_();
|
||||
_o.if_ = this.if_();
|
||||
_o.switch_ = this.switch_();
|
||||
_o.enum_ = this.enum_();
|
||||
_o.enum2 = this.enum2();
|
||||
_o.enum3 = this.enum3();
|
||||
_o.reflect = (this.reflect() !== null ? this.reflect().unpack() : null);
|
||||
}
|
||||
}
|
||||
export class Object_T {
|
||||
constructor(return_ = 0, if_ = 0, switch_ = 0, enum_ = class_.new_, enum2 = foobar_class_.arguments_, enum3 = Abc.a, reflect = null) {
|
||||
this.return_ = return_;
|
||||
this.if_ = if_;
|
||||
this.switch_ = switch_;
|
||||
this.enum_ = enum_;
|
||||
this.enum2 = enum2;
|
||||
this.enum3 = enum3;
|
||||
this.reflect = reflect;
|
||||
}
|
||||
pack(builder) {
|
||||
const reflect = (this.reflect !== null ? this.reflect.pack(builder) : 0);
|
||||
Object_.startObject(builder);
|
||||
Object_.addReturn(builder, this.return_);
|
||||
Object_.addIf(builder, this.if_);
|
||||
Object_.addSwitch(builder, this.switch_);
|
||||
Object_.addEnum(builder, this.enum_);
|
||||
Object_.addEnum2(builder, this.enum2);
|
||||
Object_.addEnum3(builder, this.enum3);
|
||||
Object_.addReflect(builder, reflect);
|
||||
return Object_.endObject(builder);
|
||||
}
|
||||
}
|
||||
226
tests/ts/typescript_keywords_generated.ts
Normal file
226
tests/ts/typescript_keywords_generated.ts
Normal file
@@ -0,0 +1,226 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import {Schema as Schema, SchemaT as SchemaT} from './reflection_generated.js';
|
||||
import {class_ as foobar_class_} from './typescript_include_generated.js';
|
||||
import {Abc as Abc} from './typescript_transitive_include_generated.js';
|
||||
|
||||
export enum class_ {
|
||||
new_ = 0,
|
||||
instanceof_ = 1
|
||||
}
|
||||
|
||||
export class Object_ {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Object_ {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsObject(bb:flatbuffers.ByteBuffer, obj?:Object_):Object_ {
|
||||
return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsObject(bb:flatbuffers.ByteBuffer, obj?:Object_):Object_ {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
return_():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_return(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
if_():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_if(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
switch_():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_switch(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
enum_():class_ {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : class_.new_;
|
||||
}
|
||||
|
||||
mutate_enum(value:class_):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
enum2():foobar_class_ {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : foobar_class_.arguments_;
|
||||
}
|
||||
|
||||
mutate_enum2(value:foobar_class_):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
enum3():Abc {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : Abc.a;
|
||||
}
|
||||
|
||||
mutate_enum3(value:Abc):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
reflect(obj?:Schema):Schema|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 16);
|
||||
return offset ? (obj || new Schema()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'typescript_Object';
|
||||
}
|
||||
|
||||
static startObject(builder:flatbuffers.Builder) {
|
||||
builder.startObject(7);
|
||||
}
|
||||
|
||||
static addReturn(builder:flatbuffers.Builder, return_:number) {
|
||||
builder.addFieldInt32(0, return_, 0);
|
||||
}
|
||||
|
||||
static addIf(builder:flatbuffers.Builder, if_:number) {
|
||||
builder.addFieldInt32(1, if_, 0);
|
||||
}
|
||||
|
||||
static addSwitch(builder:flatbuffers.Builder, switch_:number) {
|
||||
builder.addFieldInt32(2, switch_, 0);
|
||||
}
|
||||
|
||||
static addEnum(builder:flatbuffers.Builder, enum_:class_) {
|
||||
builder.addFieldInt32(3, enum_, class_.new_);
|
||||
}
|
||||
|
||||
static addEnum2(builder:flatbuffers.Builder, enum2:foobar_class_) {
|
||||
builder.addFieldInt32(4, enum2, foobar_class_.arguments_);
|
||||
}
|
||||
|
||||
static addEnum3(builder:flatbuffers.Builder, enum3:Abc) {
|
||||
builder.addFieldInt32(5, enum3, Abc.a);
|
||||
}
|
||||
|
||||
static addReflect(builder:flatbuffers.Builder, reflectOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(6, reflectOffset, 0);
|
||||
}
|
||||
|
||||
static endObject(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
unpack(): Object_T {
|
||||
return new Object_T(
|
||||
this.return_(),
|
||||
this.if_(),
|
||||
this.switch_(),
|
||||
this.enum_(),
|
||||
this.enum2(),
|
||||
this.enum3(),
|
||||
(this.reflect() !== null ? this.reflect()!.unpack() : null)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: Object_T): void {
|
||||
_o.return_ = this.return_();
|
||||
_o.if_ = this.if_();
|
||||
_o.switch_ = this.switch_();
|
||||
_o.enum_ = this.enum_();
|
||||
_o.enum2 = this.enum2();
|
||||
_o.enum3 = this.enum3();
|
||||
_o.reflect = (this.reflect() !== null ? this.reflect()!.unpack() : null);
|
||||
}
|
||||
}
|
||||
|
||||
export class Object_T {
|
||||
constructor(
|
||||
public return_: number = 0,
|
||||
public if_: number = 0,
|
||||
public switch_: number = 0,
|
||||
public enum_: class_ = class_.new_,
|
||||
public enum2: foobar_class_ = foobar_class_.arguments_,
|
||||
public enum3: Abc = Abc.a,
|
||||
public reflect: SchemaT|null = null
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const reflect = (this.reflect !== null ? this.reflect!.pack(builder) : 0);
|
||||
|
||||
Object_.startObject(builder);
|
||||
Object_.addReturn(builder, this.return_);
|
||||
Object_.addIf(builder, this.if_);
|
||||
Object_.addSwitch(builder, this.switch_);
|
||||
Object_.addEnum(builder, this.enum_);
|
||||
Object_.addEnum2(builder, this.enum2);
|
||||
Object_.addEnum3(builder, this.enum3);
|
||||
Object_.addReflect(builder, reflect);
|
||||
|
||||
return Object_.endObject(builder);
|
||||
}
|
||||
}
|
||||
|
||||
5
tests/ts/typescript_transitive_include_generated.js
Normal file
5
tests/ts/typescript_transitive_include_generated.js
Normal file
@@ -0,0 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
export var Abc;
|
||||
(function (Abc) {
|
||||
Abc[Abc["a"] = 0] = "a";
|
||||
})(Abc || (Abc = {}));
|
||||
7
tests/ts/typescript_transitive_include_generated.ts
Normal file
7
tests/ts/typescript_transitive_include_generated.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
export enum Abc {
|
||||
a = 0
|
||||
}
|
||||
|
||||
BIN
tests/ts/unicode_test.mon
Normal file
BIN
tests/ts/unicode_test.mon
Normal file
Binary file not shown.
64
tests/ts/union_vector/attacker.js
Normal file
64
tests/ts/union_vector/attacker.js
Normal file
@@ -0,0 +1,64 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
export class Attacker {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsAttacker(bb, obj) {
|
||||
return (obj || new Attacker()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsAttacker(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Attacker()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
swordAttackDamage() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_sword_attack_damage(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'Attacker';
|
||||
}
|
||||
static startAttacker(builder) {
|
||||
builder.startObject(1);
|
||||
}
|
||||
static addSwordAttackDamage(builder, swordAttackDamage) {
|
||||
builder.addFieldInt32(0, swordAttackDamage, 0);
|
||||
}
|
||||
static endAttacker(builder) {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
static createAttacker(builder, swordAttackDamage) {
|
||||
Attacker.startAttacker(builder);
|
||||
Attacker.addSwordAttackDamage(builder, swordAttackDamage);
|
||||
return Attacker.endAttacker(builder);
|
||||
}
|
||||
unpack() {
|
||||
return new AttackerT(this.swordAttackDamage());
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.swordAttackDamage = this.swordAttackDamage();
|
||||
}
|
||||
}
|
||||
export class AttackerT {
|
||||
constructor(swordAttackDamage = 0) {
|
||||
this.swordAttackDamage = swordAttackDamage;
|
||||
}
|
||||
pack(builder) {
|
||||
return Attacker.createAttacker(builder, this.swordAttackDamage);
|
||||
}
|
||||
}
|
||||
87
tests/ts/union_vector/attacker.ts
Normal file
87
tests/ts/union_vector/attacker.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
export class Attacker {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Attacker {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsAttacker(bb:flatbuffers.ByteBuffer, obj?:Attacker):Attacker {
|
||||
return (obj || new Attacker()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsAttacker(bb:flatbuffers.ByteBuffer, obj?:Attacker):Attacker {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Attacker()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
swordAttackDamage():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_sword_attack_damage(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'Attacker';
|
||||
}
|
||||
|
||||
static startAttacker(builder:flatbuffers.Builder) {
|
||||
builder.startObject(1);
|
||||
}
|
||||
|
||||
static addSwordAttackDamage(builder:flatbuffers.Builder, swordAttackDamage:number) {
|
||||
builder.addFieldInt32(0, swordAttackDamage, 0);
|
||||
}
|
||||
|
||||
static endAttacker(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createAttacker(builder:flatbuffers.Builder, swordAttackDamage:number):flatbuffers.Offset {
|
||||
Attacker.startAttacker(builder);
|
||||
Attacker.addSwordAttackDamage(builder, swordAttackDamage);
|
||||
return Attacker.endAttacker(builder);
|
||||
}
|
||||
|
||||
unpack(): AttackerT {
|
||||
return new AttackerT(
|
||||
this.swordAttackDamage()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: AttackerT): void {
|
||||
_o.swordAttackDamage = this.swordAttackDamage();
|
||||
}
|
||||
}
|
||||
|
||||
export class AttackerT {
|
||||
constructor(
|
||||
public swordAttackDamage: number = 0
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return Attacker.createAttacker(builder,
|
||||
this.swordAttackDamage
|
||||
);
|
||||
}
|
||||
}
|
||||
44
tests/ts/union_vector/book-reader.js
Normal file
44
tests/ts/union_vector/book-reader.js
Normal file
@@ -0,0 +1,44 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
export class BookReader {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
booksRead() {
|
||||
return this.bb.readInt32(this.bb_pos);
|
||||
}
|
||||
mutate_books_read(value) {
|
||||
this.bb.writeInt32(this.bb_pos + 0, value);
|
||||
return true;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'BookReader';
|
||||
}
|
||||
static sizeOf() {
|
||||
return 4;
|
||||
}
|
||||
static createBookReader(builder, books_read) {
|
||||
builder.prep(4, 4);
|
||||
builder.writeInt32(books_read);
|
||||
return builder.offset();
|
||||
}
|
||||
unpack() {
|
||||
return new BookReaderT(this.booksRead());
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.booksRead = this.booksRead();
|
||||
}
|
||||
}
|
||||
export class BookReaderT {
|
||||
constructor(booksRead = 0) {
|
||||
this.booksRead = booksRead;
|
||||
}
|
||||
pack(builder) {
|
||||
return BookReader.createBookReader(builder, this.booksRead);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user