forked from BigfootDev/flatbuffers
Compare commits
20 Commits
push-lmlon
...
bigfoot
| Author | SHA1 | Date | |
|---|---|---|---|
| 505ec2fb6a | |||
| 19aa2ce420 | |||
| 35665b5ae7 | |||
| 9e9f5bbfcf | |||
| 4edfa03ffc | |||
|
|
03fffb25e2 | ||
|
|
1a7495a6dd | ||
|
|
3c1bb67ae1 | ||
|
|
5b9de8b6c0 | ||
|
|
ea0a73d168 | ||
|
|
4623cfa4bc | ||
|
|
9c2c56dc6a | ||
|
|
429c28c783 | ||
|
|
e5a9ff757f | ||
|
|
e53732b9b9 | ||
|
|
b84b676c89 | ||
|
|
3211f857d1 | ||
|
|
95ff1f1d80 | ||
|
|
af8997b567 | ||
|
|
0d67abde45 |
5
.github/workflows/build.yml
vendored
5
.github/workflows/build.yml
vendored
@@ -197,8 +197,7 @@ jobs:
|
||||
configuration: [
|
||||
'',
|
||||
'-p:UnsafeByteBuffer=true',
|
||||
# Fails two tests currently.
|
||||
#'-p:EnableSpanT=true,UnsafeByteBuffer=true'
|
||||
'-p:EnableSpanT=true,UnsafeByteBuffer=true'
|
||||
]
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
@@ -209,7 +208,7 @@ jobs:
|
||||
- name: Build
|
||||
run: |
|
||||
cd tests\FlatBuffers.Test
|
||||
dotnet new sln --force --name FlatBuffers.Test
|
||||
dotnet new sln --force --name FlatBuffers.Test --format sln
|
||||
dotnet sln FlatBuffers.Test.sln add FlatBuffers.Test.csproj
|
||||
dotnet build -c Release ${{matrix.configuration}} FlatBuffers.Test.sln
|
||||
- name: Run net6.0
|
||||
|
||||
@@ -240,6 +240,9 @@ set(FlatBuffers_Tests_SRCS
|
||||
tests/vector_table_naked_ptr_test.cpp
|
||||
tests/native_type_test_impl.h
|
||||
tests/native_type_test_impl.cpp
|
||||
tests/cpp_vec_type_test_impl.h
|
||||
tests/cpp_vec_type_native_type_test_impl.h
|
||||
tests/cpp_vec_type_native_type_test_impl.cpp
|
||||
tests/alignment_test.h
|
||||
tests/alignment_test.cpp
|
||||
tests/64bit/offset64_test.h
|
||||
@@ -554,6 +557,8 @@ if(FLATBUFFERS_BUILD_TESTS)
|
||||
compile_schema_for_test(tests/arrays_test.fbs "${FLATC_OPT_SCOPED_ENUMS}")
|
||||
compile_schema_for_test(tests/native_inline_table_test.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/native_type_test.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/cpp_vec_type_test.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/cpp_vec_type_native_type_test.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/key_field/key_field_sample.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/64bit/test_64bit.fbs "${FLATC_OPT_COMP};--bfbs-gen-embed")
|
||||
compile_schema_for_test(tests/64bit/evolution/v1.fbs "${FLATC_OPT_COMP}")
|
||||
|
||||
@@ -50,6 +50,7 @@ bazel_dep(
|
||||
bazel_dep(
|
||||
name = "rules_swift",
|
||||
version = "2.1.1",
|
||||
max_compatibility_level = 3,
|
||||
repo_name = "build_bazel_rules_swift",
|
||||
)
|
||||
bazel_dep(
|
||||
|
||||
@@ -79,11 +79,12 @@ list of `FILES...`.
|
||||
`myschema.fbs` to JSON:
|
||||
|
||||
```sh
|
||||
flatc --json myschema.fbs mydata.bin
|
||||
flatc --json myschema.fbs -- mydata.bin
|
||||
```
|
||||
|
||||
This will generate a `mydata.json` file.
|
||||
|
||||
This will generate a `mydata.json` file. If there is no
|
||||
[`file_identifier`](schema.md/#file-identification-and-extension) defined
|
||||
for this schema, you will need to use the `--raw-binary` option.
|
||||
|
||||
### Additional options
|
||||
|
||||
|
||||
@@ -1134,12 +1134,8 @@ The Builder provides multiple ways to create `vectors`.
|
||||
=== "Python"
|
||||
|
||||
```py
|
||||
# Create a FlatBuffer vector and prepend the weapons.
|
||||
# Note: Since we prepend the data, prepend them in reverse order.
|
||||
MyGame.Sample.Monster.StartWeaponsVector(builder, 2)
|
||||
builder.PrependUOffsetTRelative(axe)
|
||||
builder.PrependUOffsetTRelative(sword)
|
||||
weapons = builder.EndVector()
|
||||
# Use the generated helper to create the weapons vector from offsets.
|
||||
weapons = MyGame.Sample.Monster.CreateWeaponsVector(builder, [sword, axe])
|
||||
```
|
||||
|
||||
=== "Rust"
|
||||
@@ -1352,16 +1348,13 @@ bit more directly.
|
||||
```py
|
||||
# Create a `vector` representing the inventory of the Orc. Each number
|
||||
# could correspond to an item that can be claimed after he is slain.
|
||||
# Note: Since we prepend the bytes, this loop iterates in reverse.
|
||||
MyGame.Sample.Monster.StartInventoryVector(builder, 10)
|
||||
for i in reversed(range(0, 10)):
|
||||
builder.PrependByte(i)
|
||||
inv = builder.EndVector()
|
||||
inv = MyGame.Sample.Monster.CreateInventoryVector(builder, range(0, 10))
|
||||
|
||||
MyGame.Sample.Monster.StartPathVector(builder, 2)
|
||||
MyGame.Sample.Vec3.CreateVec3(builder, 1.0, 2.0, 3.0)
|
||||
MyGame.Sample.Vec3.CreateVec3(builder, 4.0, 5.0, 6.0)
|
||||
path = builder.EndVector()
|
||||
path_points = [
|
||||
MyGame.Sample.Vec3T(x=1.0, y=2.0, z=3.0),
|
||||
MyGame.Sample.Vec3T(x=4.0, y=5.0, z=6.0),
|
||||
]
|
||||
path = MyGame.Sample.Monster.CreatePathVector(builder, path_points)
|
||||
```
|
||||
|
||||
=== "Rust"
|
||||
|
||||
@@ -80,6 +80,12 @@ def UniverseStartGalaxiesVector(builder, numElems):
|
||||
def StartGalaxiesVector(builder, numElems):
|
||||
return UniverseStartGalaxiesVector(builder, numElems)
|
||||
|
||||
def UniverseCreateGalaxiesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateGalaxiesVector(builder, data):
|
||||
UniverseCreateGalaxiesVector(builder, data)
|
||||
|
||||
def UniverseEnd(builder):
|
||||
return builder.EndObject()
|
||||
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
#[allow(unused_imports, dead_code)]
|
||||
pub mod flatbuffers {
|
||||
|
||||
extern crate alloc;
|
||||
#[allow(unused_imports, dead_code)]
|
||||
pub mod goldens {
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
pub enum GalaxyOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
@@ -260,15 +260,15 @@ inline const char* flatbuffers_version_string() {
|
||||
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator ~ (E lhs){\
|
||||
return E(~T(lhs));\
|
||||
}\
|
||||
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator |= (E &lhs, E rhs){\
|
||||
inline FLATBUFFERS_CONSTEXPR_CPP14 E operator |= (E &lhs, E rhs){\
|
||||
lhs = lhs | rhs;\
|
||||
return lhs;\
|
||||
}\
|
||||
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator &= (E &lhs, E rhs){\
|
||||
inline FLATBUFFERS_CONSTEXPR_CPP14 E operator &= (E &lhs, E rhs){\
|
||||
lhs = lhs & rhs;\
|
||||
return lhs;\
|
||||
}\
|
||||
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator ^= (E &lhs, E rhs){\
|
||||
inline FLATBUFFERS_CONSTEXPR_CPP14 E operator ^= (E &lhs, E rhs){\
|
||||
lhs = lhs ^ rhs;\
|
||||
return lhs;\
|
||||
}\
|
||||
|
||||
@@ -223,7 +223,7 @@ struct Type {
|
||||
uint16_t fixed_length; // only set if t == BASE_TYPE_ARRAY
|
||||
};
|
||||
|
||||
// Represents a parsed scalar value, it's type, and field offset.
|
||||
// Represents a parsed scalar value, its type, and field offset.
|
||||
struct Value {
|
||||
Value()
|
||||
: constant("0"),
|
||||
@@ -395,13 +395,20 @@ struct FieldDef : public Definition {
|
||||
};
|
||||
|
||||
struct StructDef : public Definition {
|
||||
enum class CycleStatus {
|
||||
NotChecked,
|
||||
InProgress,
|
||||
Checked,
|
||||
};
|
||||
|
||||
StructDef()
|
||||
: fixed(false),
|
||||
predecl(true),
|
||||
sortbysize(true),
|
||||
has_key(false),
|
||||
minalign(1),
|
||||
bytesize(0) {}
|
||||
bytesize(0),
|
||||
cycle_status{CycleStatus::NotChecked} {}
|
||||
|
||||
void PadLastField(size_t min_align) {
|
||||
auto padding = PaddingBytes(bytesize, min_align);
|
||||
@@ -423,6 +430,8 @@ struct StructDef : public Definition {
|
||||
size_t minalign; // What the whole object needs to be aligned to.
|
||||
size_t bytesize; // Size if fixed.
|
||||
|
||||
CycleStatus cycle_status; // used for determining if we have circular references
|
||||
|
||||
flatbuffers::unique_ptr<std::string> original_location;
|
||||
std::vector<voffset_t> reserved_ids;
|
||||
};
|
||||
@@ -667,6 +676,7 @@ struct IDLOptions {
|
||||
bool gen_absl_hash;
|
||||
std::string cpp_object_api_pointer_type;
|
||||
std::string cpp_object_api_string_type;
|
||||
std::string cpp_object_api_vector_type;
|
||||
bool cpp_object_api_string_flexible_constructor;
|
||||
CaseStyle cpp_object_api_field_case_style;
|
||||
bool cpp_direct_copy;
|
||||
@@ -734,6 +744,7 @@ struct IDLOptions {
|
||||
bool python_gen_numpy;
|
||||
|
||||
bool ts_omit_entrypoint;
|
||||
bool ts_undefined_for_optionals;
|
||||
ProtoIdGapAction proto_id_gap_action;
|
||||
|
||||
// Possible options for the more general generator below.
|
||||
@@ -860,6 +871,7 @@ struct IDLOptions {
|
||||
python_typing(false),
|
||||
python_gen_numpy(true),
|
||||
ts_omit_entrypoint(false),
|
||||
ts_undefined_for_optionals(false),
|
||||
proto_id_gap_action(ProtoIdGapAction::WARNING),
|
||||
mini_reflect(IDLOptions::kNone),
|
||||
require_explicit_ids(false),
|
||||
@@ -1001,6 +1013,7 @@ class Parser : public ParserState {
|
||||
known_attributes_["cpp_ptr_type_get"] = true;
|
||||
known_attributes_["cpp_str_type"] = true;
|
||||
known_attributes_["cpp_str_flex_ctor"] = true;
|
||||
known_attributes_["cpp_vec_type"] = true;
|
||||
known_attributes_["native_inline"] = true;
|
||||
known_attributes_["native_custom_alloc"] = true;
|
||||
known_attributes_["native_type"] = true;
|
||||
@@ -1099,6 +1112,8 @@ class Parser : public ParserState {
|
||||
// others includes.
|
||||
std::vector<IncludedFile> GetIncludedFiles() const;
|
||||
|
||||
bool HasCircularStructDependency();
|
||||
|
||||
private:
|
||||
class ParseDepthGuard;
|
||||
|
||||
|
||||
@@ -14,9 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("NOTHING_TO_INLINE")
|
||||
@file:OptIn(ExperimentalNativeApi::class)
|
||||
|
||||
package com.google.flatbuffers.kotlin
|
||||
|
||||
import kotlin.experimental.ExperimentalNativeApi
|
||||
|
||||
/**
|
||||
* This implementation assumes that of native macOSX64 the byte order of the implementation is
|
||||
* Little Endian.
|
||||
|
||||
@@ -296,25 +296,62 @@ function mt:Slot(slotnum)
|
||||
self.currentVTable[slotnum + 1] = self:Offset()
|
||||
end
|
||||
|
||||
local function finish(self, rootTable, sizePrefix)
|
||||
local function finish(self, rootTable, sizePrefix, fileIdentifier)
|
||||
UOffsetT:EnforceNumber(rootTable)
|
||||
self:Prep(self.minalign, sizePrefix and 8 or 4)
|
||||
self:PrependUOffsetTRelative(rootTable)
|
||||
local hasFid = fileIdentifier ~= nil
|
||||
if hasFid then
|
||||
assert(#fileIdentifier == 4, "File identifier must be exactly 4 bytes")
|
||||
end
|
||||
|
||||
local fid_byte_count = (hasFid and 4 or 0)
|
||||
|
||||
-- alignment:
|
||||
-- root offset (4)
|
||||
-- optional file id (4)
|
||||
-- optional size prefix (4)
|
||||
self:Prep(
|
||||
self.minalign,
|
||||
(sizePrefix and 4 or 0) +
|
||||
4 +
|
||||
fid_byte_count
|
||||
)
|
||||
|
||||
-- root offset (points past file identifier if present)
|
||||
self:PrependUOffsetTRelative(rootTable + fid_byte_count)
|
||||
|
||||
-- file identifier
|
||||
if hasFid then
|
||||
for i = 4, 1, -1 do
|
||||
self:PrependByte(string.byte(fileIdentifier, i))
|
||||
end
|
||||
end
|
||||
|
||||
-- size prefix
|
||||
if sizePrefix then
|
||||
local size = self.bytes.size - self.head
|
||||
Int32:EnforceNumber(size)
|
||||
self:PrependInt32(size)
|
||||
end
|
||||
|
||||
self.finished = true
|
||||
return self.head
|
||||
end
|
||||
|
||||
|
||||
function mt:Finish(rootTable)
|
||||
return finish(self, rootTable, false)
|
||||
return finish(self, rootTable, false, nil)
|
||||
end
|
||||
|
||||
function mt:FinishSizePrefixed(rootTable)
|
||||
return finish(self, rootTable, true)
|
||||
return finish(self, rootTable, true, nil)
|
||||
end
|
||||
|
||||
function mt:FinishWithIdentifier(rootTable, fileIdentifier)
|
||||
return finish(self, rootTable, false, fileIdentifier)
|
||||
end
|
||||
|
||||
function mt:FinishSizePrefixedWithIdentifier(rootTable, fileIdentifier)
|
||||
return finish(self, rootTable, true, fileIdentifier)
|
||||
end
|
||||
|
||||
function mt:Prepend(flags, off)
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace Google.FlatBuffers
|
||||
|
||||
var pos = this.__vector(o);
|
||||
var len = this.__vector_len(o);
|
||||
return bb.ToArray<T>(pos, len);
|
||||
return bb.ToArray<T>(pos, len * ByteBuffer.SizeOf<T>());
|
||||
}
|
||||
|
||||
// Initialize any Table-derived type to point to the union at the given offset.
|
||||
|
||||
@@ -422,7 +422,6 @@ class Builder(object):
|
||||
off2 = self.Offset() - off + N.UOffsetTFlags.bytewidth
|
||||
self.PlaceUOffsetT(off2)
|
||||
|
||||
## @cond FLATBUFFERS_INTERNAL
|
||||
def StartVector(self, elemSize, numElems, alignment):
|
||||
"""StartVector initializes bookkeeping for writing a new vector.
|
||||
|
||||
@@ -438,8 +437,6 @@ class Builder(object):
|
||||
self.Prep(alignment, elemSize * numElems) # In case alignment > int.
|
||||
return self.Offset()
|
||||
|
||||
## @endcond
|
||||
|
||||
def EndVector(self, numElems=None):
|
||||
"""EndVector writes data necessary to finish vector construction."""
|
||||
|
||||
@@ -556,6 +553,21 @@ class Builder(object):
|
||||
self.vectorNumElems = x.size
|
||||
return self.EndVector()
|
||||
|
||||
def CreateVectorOfTables(self, offsets):
|
||||
"""CreateVectorOfTables writes a vector of offsets such as tables or strings.
|
||||
|
||||
Args:
|
||||
offsets: Iterable of offsets returned from previous builder operations.
|
||||
Each element should be an integer compatible with UOffsetT.
|
||||
"""
|
||||
|
||||
offsets = list(offsets)
|
||||
self.StartVector(N.UOffsetTFlags.bytewidth, len(offsets),
|
||||
N.UOffsetTFlags.bytewidth)
|
||||
for off in reversed(offsets):
|
||||
self.PrependUOffsetTRelative(off)
|
||||
return self.EndVector()
|
||||
|
||||
## @cond FLATBUFFERS_INTERNAL
|
||||
def assertNested(self):
|
||||
"""Check that we are in the process of building an object."""
|
||||
|
||||
@@ -155,6 +155,12 @@ def EnumStartValuesVector(builder, numElems):
|
||||
def StartValuesVector(builder, numElems):
|
||||
return EnumStartValuesVector(builder, numElems)
|
||||
|
||||
def EnumCreateValuesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateValuesVector(builder, data):
|
||||
EnumCreateValuesVector(builder, data)
|
||||
|
||||
def EnumAddIsUnion(builder, isUnion):
|
||||
builder.PrependBoolSlot(2, isUnion, 0)
|
||||
|
||||
@@ -179,6 +185,12 @@ def EnumStartAttributesVector(builder, numElems):
|
||||
def StartAttributesVector(builder, numElems):
|
||||
return EnumStartAttributesVector(builder, numElems)
|
||||
|
||||
def EnumCreateAttributesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateAttributesVector(builder, data):
|
||||
EnumCreateAttributesVector(builder, data)
|
||||
|
||||
def EnumAddDocumentation(builder, documentation):
|
||||
builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0)
|
||||
|
||||
@@ -191,6 +203,12 @@ def EnumStartDocumentationVector(builder, numElems):
|
||||
def StartDocumentationVector(builder, numElems):
|
||||
return EnumStartDocumentationVector(builder, numElems)
|
||||
|
||||
def EnumCreateDocumentationVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateDocumentationVector(builder, data):
|
||||
EnumCreateDocumentationVector(builder, data)
|
||||
|
||||
def EnumAddDeclarationFile(builder, declarationFile):
|
||||
builder.PrependUOffsetTRelativeSlot(6, flatbuffers.number_types.UOffsetTFlags.py_type(declarationFile), 0)
|
||||
|
||||
|
||||
@@ -134,6 +134,12 @@ def EnumValStartDocumentationVector(builder, numElems):
|
||||
def StartDocumentationVector(builder, numElems):
|
||||
return EnumValStartDocumentationVector(builder, numElems)
|
||||
|
||||
def EnumValCreateDocumentationVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateDocumentationVector(builder, data):
|
||||
EnumValCreateDocumentationVector(builder, data)
|
||||
|
||||
def EnumValAddAttributes(builder, attributes):
|
||||
builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0)
|
||||
|
||||
@@ -146,6 +152,12 @@ def EnumValStartAttributesVector(builder, numElems):
|
||||
def StartAttributesVector(builder, numElems):
|
||||
return EnumValStartAttributesVector(builder, numElems)
|
||||
|
||||
def EnumValCreateAttributesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateAttributesVector(builder, data):
|
||||
EnumValCreateAttributesVector(builder, data)
|
||||
|
||||
def EnumValEnd(builder):
|
||||
return builder.EndObject()
|
||||
|
||||
|
||||
@@ -235,6 +235,12 @@ def FieldStartAttributesVector(builder, numElems):
|
||||
def StartAttributesVector(builder, numElems):
|
||||
return FieldStartAttributesVector(builder, numElems)
|
||||
|
||||
def FieldCreateAttributesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateAttributesVector(builder, data):
|
||||
FieldCreateAttributesVector(builder, data)
|
||||
|
||||
def FieldAddDocumentation(builder, documentation):
|
||||
builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0)
|
||||
|
||||
@@ -247,6 +253,12 @@ def FieldStartDocumentationVector(builder, numElems):
|
||||
def StartDocumentationVector(builder, numElems):
|
||||
return FieldStartDocumentationVector(builder, numElems)
|
||||
|
||||
def FieldCreateDocumentationVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateDocumentationVector(builder, data):
|
||||
FieldCreateDocumentationVector(builder, data)
|
||||
|
||||
def FieldAddOptional(builder, optional):
|
||||
builder.PrependBoolSlot(11, optional, 0)
|
||||
|
||||
|
||||
@@ -158,6 +158,12 @@ def ObjectStartFieldsVector(builder, numElems):
|
||||
def StartFieldsVector(builder, numElems):
|
||||
return ObjectStartFieldsVector(builder, numElems)
|
||||
|
||||
def ObjectCreateFieldsVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateFieldsVector(builder, data):
|
||||
ObjectCreateFieldsVector(builder, data)
|
||||
|
||||
def ObjectAddIsStruct(builder, isStruct):
|
||||
builder.PrependBoolSlot(2, isStruct, 0)
|
||||
|
||||
@@ -188,6 +194,12 @@ def ObjectStartAttributesVector(builder, numElems):
|
||||
def StartAttributesVector(builder, numElems):
|
||||
return ObjectStartAttributesVector(builder, numElems)
|
||||
|
||||
def ObjectCreateAttributesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateAttributesVector(builder, data):
|
||||
ObjectCreateAttributesVector(builder, data)
|
||||
|
||||
def ObjectAddDocumentation(builder, documentation):
|
||||
builder.PrependUOffsetTRelativeSlot(6, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0)
|
||||
|
||||
@@ -200,6 +212,12 @@ def ObjectStartDocumentationVector(builder, numElems):
|
||||
def StartDocumentationVector(builder, numElems):
|
||||
return ObjectStartDocumentationVector(builder, numElems)
|
||||
|
||||
def ObjectCreateDocumentationVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateDocumentationVector(builder, data):
|
||||
ObjectCreateDocumentationVector(builder, data)
|
||||
|
||||
def ObjectAddDeclarationFile(builder, declarationFile):
|
||||
builder.PrependUOffsetTRelativeSlot(7, flatbuffers.number_types.UOffsetTFlags.py_type(declarationFile), 0)
|
||||
|
||||
|
||||
@@ -138,6 +138,12 @@ def RPCCallStartAttributesVector(builder, numElems):
|
||||
def StartAttributesVector(builder, numElems):
|
||||
return RPCCallStartAttributesVector(builder, numElems)
|
||||
|
||||
def RPCCallCreateAttributesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateAttributesVector(builder, data):
|
||||
RPCCallCreateAttributesVector(builder, data)
|
||||
|
||||
def RPCCallAddDocumentation(builder, documentation):
|
||||
builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0)
|
||||
|
||||
@@ -150,6 +156,12 @@ def RPCCallStartDocumentationVector(builder, numElems):
|
||||
def StartDocumentationVector(builder, numElems):
|
||||
return RPCCallStartDocumentationVector(builder, numElems)
|
||||
|
||||
def RPCCallCreateDocumentationVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateDocumentationVector(builder, data):
|
||||
RPCCallCreateDocumentationVector(builder, data)
|
||||
|
||||
def RPCCallEnd(builder):
|
||||
return builder.EndObject()
|
||||
|
||||
|
||||
@@ -180,6 +180,12 @@ def SchemaStartObjectsVector(builder, numElems):
|
||||
def StartObjectsVector(builder, numElems):
|
||||
return SchemaStartObjectsVector(builder, numElems)
|
||||
|
||||
def SchemaCreateObjectsVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateObjectsVector(builder, data):
|
||||
SchemaCreateObjectsVector(builder, data)
|
||||
|
||||
def SchemaAddEnums(builder, enums):
|
||||
builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(enums), 0)
|
||||
|
||||
@@ -192,6 +198,12 @@ def SchemaStartEnumsVector(builder, numElems):
|
||||
def StartEnumsVector(builder, numElems):
|
||||
return SchemaStartEnumsVector(builder, numElems)
|
||||
|
||||
def SchemaCreateEnumsVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateEnumsVector(builder, data):
|
||||
SchemaCreateEnumsVector(builder, data)
|
||||
|
||||
def SchemaAddFileIdent(builder, fileIdent):
|
||||
builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(fileIdent), 0)
|
||||
|
||||
@@ -222,6 +234,12 @@ def SchemaStartServicesVector(builder, numElems):
|
||||
def StartServicesVector(builder, numElems):
|
||||
return SchemaStartServicesVector(builder, numElems)
|
||||
|
||||
def SchemaCreateServicesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateServicesVector(builder, data):
|
||||
SchemaCreateServicesVector(builder, data)
|
||||
|
||||
def SchemaAddAdvancedFeatures(builder, advancedFeatures):
|
||||
builder.PrependUint64Slot(6, advancedFeatures, 0)
|
||||
|
||||
@@ -240,6 +258,12 @@ def SchemaStartFbsFilesVector(builder, numElems):
|
||||
def StartFbsFilesVector(builder, numElems):
|
||||
return SchemaStartFbsFilesVector(builder, numElems)
|
||||
|
||||
def SchemaCreateFbsFilesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateFbsFilesVector(builder, data):
|
||||
SchemaCreateFbsFilesVector(builder, data)
|
||||
|
||||
def SchemaEnd(builder):
|
||||
return builder.EndObject()
|
||||
|
||||
|
||||
@@ -84,6 +84,12 @@ def SchemaFileStartIncludedFilenamesVector(builder, numElems):
|
||||
def StartIncludedFilenamesVector(builder, numElems):
|
||||
return SchemaFileStartIncludedFilenamesVector(builder, numElems)
|
||||
|
||||
def SchemaFileCreateIncludedFilenamesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateIncludedFilenamesVector(builder, data):
|
||||
SchemaFileCreateIncludedFilenamesVector(builder, data)
|
||||
|
||||
def SchemaFileEnd(builder):
|
||||
return builder.EndObject()
|
||||
|
||||
|
||||
@@ -137,6 +137,12 @@ def ServiceStartCallsVector(builder, numElems):
|
||||
def StartCallsVector(builder, numElems):
|
||||
return ServiceStartCallsVector(builder, numElems)
|
||||
|
||||
def ServiceCreateCallsVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateCallsVector(builder, data):
|
||||
ServiceCreateCallsVector(builder, data)
|
||||
|
||||
def ServiceAddAttributes(builder, attributes):
|
||||
builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0)
|
||||
|
||||
@@ -149,6 +155,12 @@ def ServiceStartAttributesVector(builder, numElems):
|
||||
def StartAttributesVector(builder, numElems):
|
||||
return ServiceStartAttributesVector(builder, numElems)
|
||||
|
||||
def ServiceCreateAttributesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateAttributesVector(builder, data):
|
||||
ServiceCreateAttributesVector(builder, data)
|
||||
|
||||
def ServiceAddDocumentation(builder, documentation):
|
||||
builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0)
|
||||
|
||||
@@ -161,6 +173,12 @@ def ServiceStartDocumentationVector(builder, numElems):
|
||||
def StartDocumentationVector(builder, numElems):
|
||||
return ServiceStartDocumentationVector(builder, numElems)
|
||||
|
||||
def ServiceCreateDocumentationVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateDocumentationVector(builder, data):
|
||||
ServiceCreateDocumentationVector(builder, data)
|
||||
|
||||
def ServiceAddDeclarationFile(builder, declarationFile):
|
||||
builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(declarationFile), 0)
|
||||
|
||||
|
||||
@@ -611,6 +611,8 @@ impl<'fbb, A: Allocator> FlatBufferBuilder<'fbb, A> {
|
||||
// Write the VTable (we may delete it afterwards, if it is a duplicate):
|
||||
let vt_start_pos = self.head;
|
||||
let vt_end_pos = self.head + vtable_byte_len;
|
||||
// Zero out the vtable space - make_space only reserves but doesn't initialize
|
||||
self.allocator[vt_start_pos.range_to(vt_end_pos)].fill(0);
|
||||
{
|
||||
// write the vtable header:
|
||||
let vtfw =
|
||||
|
||||
@@ -421,6 +421,9 @@ impl<'a> Serializer for MapKeySerializer<'a> {
|
||||
type SerializeStruct = Impossible<(), Error>;
|
||||
type SerializeStructVariant = Impossible<(), Error>;
|
||||
|
||||
fn is_human_readable(&self) -> bool {
|
||||
self.0.is_human_readable()
|
||||
}
|
||||
fn serialize_bool(self, _value: bool) -> Result<(), Error> {
|
||||
key_must_be_a_string()
|
||||
}
|
||||
|
||||
@@ -33,11 +33,11 @@ result = subprocess.run(
|
||||
if result.returncode != 0:
|
||||
print(
|
||||
"\n"
|
||||
"ERROR: *********************************************************\n"
|
||||
"ERROR: * The following differences were found after building. *\n"
|
||||
"ERROR: * Perhaps there is a difference in the flags for the. *\n"
|
||||
"ERROR: * CMakeLists.txt vs the script/generate_code.py script? *\n"
|
||||
"ERROR: *********************************************************\n"
|
||||
"ERROR: **********************************************************\n"
|
||||
"ERROR: * The following differences were found after building. *\n"
|
||||
"ERROR: * Perhaps there is a difference in the flags for the. *\n"
|
||||
"ERROR: * CMakeLists.txt vs the scripts/generate_code.py script? *\n"
|
||||
"ERROR: **********************************************************\n"
|
||||
)
|
||||
subprocess.run(["git", "diff", "--binary", "--exit-code"], cwd=root_path)
|
||||
sys.exit(result.returncode)
|
||||
@@ -55,11 +55,11 @@ result = subprocess.run(
|
||||
if result.returncode != 0:
|
||||
print(
|
||||
"\n"
|
||||
"ERROR: ********************************************************\n"
|
||||
"ERROR: * The following differences were found after running *\n"
|
||||
"ERROR: * the script/generate_code.py script. Maybe you forgot *\n"
|
||||
"ERROR: * to run it after making changes in a generator? *\n"
|
||||
"ERROR: ********************************************************\n"
|
||||
"ERROR: *********************************************************\n"
|
||||
"ERROR: * The following differences were found after running *\n"
|
||||
"ERROR: * the scripts/generate_code.py script. Maybe you forgot *\n"
|
||||
"ERROR: * to run it after making changes in a generator? *\n"
|
||||
"ERROR: *********************************************************\n"
|
||||
)
|
||||
subprocess.run(["git", "diff", "--binary", "--exit-code"], cwd=root_path)
|
||||
sys.exit(result.returncode)
|
||||
|
||||
@@ -85,6 +85,11 @@ RUST_OPTS = BASE_OPTS + [
|
||||
"--gen-name-strings",
|
||||
"--rust-module-root-file",
|
||||
]
|
||||
RUST_STANDALONE_OPTS = BASE_OPTS + [
|
||||
"--rust",
|
||||
"--gen-all",
|
||||
"--gen-name-strings",
|
||||
]
|
||||
RUST_SERIALIZE_OPTS = BASE_OPTS + [
|
||||
"--rust",
|
||||
"--gen-all",
|
||||
@@ -288,6 +293,12 @@ flatc(
|
||||
schema="include_test/include_test1.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
RUST_STANDALONE_OPTS,
|
||||
include="include_test",
|
||||
schema="include_test/include_test1.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
RUST_OPTS,
|
||||
prefix="include_test2",
|
||||
@@ -295,6 +306,12 @@ flatc(
|
||||
schema="include_test/sub/include_test2.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
RUST_STANDALONE_OPTS,
|
||||
include="include_test",
|
||||
schema="include_test/sub/include_test2.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
BINARY_OPTS + ["--bfbs-filenames", str(tests_path)],
|
||||
include="include_test",
|
||||
@@ -366,6 +383,11 @@ flatc(
|
||||
schema="native_type_test.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
["--cpp", "--gen-compare", "--gen-mutable", "--gen-object-api", "--reflect-names"],
|
||||
schema="cpp_vec_type_test.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
[
|
||||
"--cpp",
|
||||
|
||||
@@ -195,6 +195,13 @@ class LuaBfbsGenerator : public BaseBfbsGenerator {
|
||||
code += "\n";
|
||||
|
||||
if (object == root_object) {
|
||||
// emit file identifier if present
|
||||
const auto ident = schema_->file_ident();
|
||||
if (ident && ident->size() == 4) {
|
||||
code += "local FileIdentifier = \"" + ident->str() + "\"\n";
|
||||
code += "\n";
|
||||
}
|
||||
|
||||
code += "function " + object_name + ".GetRootAs" + object_name +
|
||||
"(buf, offset)\n";
|
||||
code += " if type(buf) == \"string\" then\n";
|
||||
@@ -455,6 +462,34 @@ class LuaBfbsGenerator : public BaseBfbsGenerator {
|
||||
code += " return builder:EndObject()\n";
|
||||
code += "end\n";
|
||||
code += "\n";
|
||||
|
||||
if (object == root_object) {
|
||||
code += "function " + object_name + ".Finish" + object_name +
|
||||
"Buffer(builder, offset)\n";
|
||||
// emit file identifier if present
|
||||
const auto ident = schema_->file_ident();
|
||||
if (ident && ident->size() == 4) {
|
||||
code += " builder:FinishWithIdentifier(offset, FileIdentifier)\n";
|
||||
} else {
|
||||
code += " builder:Finish(offset)\n";
|
||||
}
|
||||
code += "end\n";
|
||||
code += "\n";
|
||||
|
||||
// size prefixed option
|
||||
code += "function " + object_name + ".FinishSizePrefixed" +
|
||||
object_name + "Buffer(builder, offset)\n";
|
||||
// emit file identifier if present
|
||||
if (ident && ident->size() == 4) {
|
||||
code +=
|
||||
" builder:FinishSizePrefixedWithIdentifier(offset, "
|
||||
"FileIdentifier)\n";
|
||||
} else {
|
||||
code += " builder:FinishSizePrefixed(offset)\n";
|
||||
}
|
||||
code += "end\n";
|
||||
code += "\n";
|
||||
}
|
||||
}
|
||||
|
||||
EmitCodeBlock(code, object_name, ns, object->declaration_file()->str());
|
||||
|
||||
@@ -142,6 +142,10 @@ const static FlatCOption flatc_options[] = {
|
||||
"and T::empty() must be supported. The custom type also needs to be "
|
||||
"constructible from std::string (see the --cpp-str-flex-ctor option to "
|
||||
"change this behavior)"},
|
||||
{"", "cpp-vec-type", "T",
|
||||
"Set object API vector type (default std::vector). T must support the "
|
||||
"same interface as std::vector: size(), resize(), reserve(), "
|
||||
"emplace_back(), operator[], begin(), end(), and data()."},
|
||||
{"", "cpp-str-flex-ctor", "",
|
||||
"Don't construct custom string types by passing std::string from "
|
||||
"Flatbuffers, but (char* + length)."},
|
||||
@@ -265,6 +269,9 @@ const static FlatCOption flatc_options[] = {
|
||||
{"", "python-gen-numpy", "", "Whether to generate numpy helpers."},
|
||||
{"", "ts-omit-entrypoint", "",
|
||||
"Omit emission of namespace entrypoint file"},
|
||||
{"", "ts-undefined-for-optionals", "",
|
||||
"Whether to generate undefined values instead of null values for missing "
|
||||
"optional keys"},
|
||||
{"", "file-names-only", "",
|
||||
"Print out generated file names without writing to the files"},
|
||||
{"", "grpc-filename-suffix", "SUFFIX",
|
||||
@@ -540,6 +547,9 @@ FlatCOptions FlatCompiler::ParseFromCommandLineArguments(int argc,
|
||||
} else if (arg == "--cpp-str-type") {
|
||||
if (++argi >= argc) Error("missing type following: " + arg, true);
|
||||
opts.cpp_object_api_string_type = argv[argi];
|
||||
} else if (arg == "--cpp-vec-type") {
|
||||
if (++argi >= argc) Error("missing type following: " + arg, true);
|
||||
opts.cpp_object_api_vector_type = argv[argi];
|
||||
} else if (arg == "--cpp-str-flex-ctor") {
|
||||
opts.cpp_object_api_string_flexible_constructor = true;
|
||||
} else if (arg == "--no-cpp-direct-copy") {
|
||||
@@ -710,6 +720,8 @@ FlatCOptions FlatCompiler::ParseFromCommandLineArguments(int argc,
|
||||
opts.python_gen_numpy = false;
|
||||
} else if (arg == "--ts-omit-entrypoint") {
|
||||
opts.ts_omit_entrypoint = true;
|
||||
} else if (arg == "--ts-undefined-for-optionals") {
|
||||
opts.ts_undefined_for_optionals = true;
|
||||
} else if (arg == "--annotate-sparse-vectors") {
|
||||
options.annotate_include_vector_contents = false;
|
||||
} else if (arg == "--annotate") {
|
||||
@@ -922,6 +934,9 @@ std::unique_ptr<Parser> FlatCompiler::GenerateCode(const FlatCOptions& options,
|
||||
auto err = parser->ConformTo(conform_parser);
|
||||
if (!err.empty()) Error("schemas don\'t conform: " + err, false);
|
||||
}
|
||||
if (parser->HasCircularStructDependency()) {
|
||||
Error("schema has circular struct dependencies: " + filename, false);
|
||||
}
|
||||
if (options.schema_binary || opts.binary_schema_gen_embed) {
|
||||
parser->Serialize();
|
||||
}
|
||||
|
||||
@@ -929,6 +929,15 @@ class CppGenerator : public BaseGenerator {
|
||||
return ret;
|
||||
}
|
||||
|
||||
const std::string NativeVector(const FieldDef* field) {
|
||||
auto attr = field ? field->attributes.Lookup("cpp_vec_type") : nullptr;
|
||||
auto& ret = attr ? attr->constant : opts_.cpp_object_api_vector_type;
|
||||
if (ret.empty()) {
|
||||
return "std::vector";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool FlexibleStringConstructor(const FieldDef* field) {
|
||||
auto attr = field != nullptr &&
|
||||
(field->attributes.Lookup("cpp_str_flex_ctor") != nullptr);
|
||||
@@ -974,20 +983,26 @@ class CppGenerator : public BaseGenerator {
|
||||
case BASE_TYPE_VECTOR64:
|
||||
case BASE_TYPE_VECTOR: {
|
||||
const auto type_name = GenTypeNative(type.VectorType(), true, field);
|
||||
if (type.struct_def &&
|
||||
const auto vec_type = NativeVector(&field);
|
||||
if (vec_type == "std::vector" && type.struct_def &&
|
||||
type.struct_def->attributes.Lookup("native_custom_alloc")) {
|
||||
auto native_custom_alloc =
|
||||
type.struct_def->attributes.Lookup("native_custom_alloc");
|
||||
return "std::vector<" + type_name + "," +
|
||||
native_custom_alloc->constant + "<" + type_name + ">>";
|
||||
} else {
|
||||
return "std::vector<" + type_name + ">";
|
||||
}
|
||||
return vec_type + "<" + type_name + ">";
|
||||
}
|
||||
case BASE_TYPE_STRUCT: {
|
||||
auto type_name = WrapInNameSpace(*type.struct_def);
|
||||
if (IsStruct(type)) {
|
||||
auto native_type = type.struct_def->attributes.Lookup("native_type");
|
||||
// Field-level native_type takes priority over struct-level
|
||||
// native_type
|
||||
auto field_native_type = field.attributes.Lookup("native_type");
|
||||
auto native_type =
|
||||
field_native_type
|
||||
? field_native_type
|
||||
: type.struct_def->attributes.Lookup("native_type");
|
||||
if (native_type) {
|
||||
type_name = native_type->constant;
|
||||
}
|
||||
@@ -1951,9 +1966,10 @@ class CppGenerator : public BaseGenerator {
|
||||
field.offset64);
|
||||
}
|
||||
if (TypeHasKey(vtype)) {
|
||||
code_.SetValue("PARAM_TYPE", "std::vector<" + type + "> *");
|
||||
code_.SetValue("PARAM_TYPE", NativeVector(&field) + "<" + type + "> *");
|
||||
} else {
|
||||
code_.SetValue("PARAM_TYPE", "const std::vector<" + type + "> *");
|
||||
code_.SetValue("PARAM_TYPE",
|
||||
"const " + NativeVector(&field) + "<" + type + "> *");
|
||||
}
|
||||
code_.SetValue("PARAM_VALUE", "nullptr");
|
||||
} else {
|
||||
@@ -1979,7 +1995,7 @@ class CppGenerator : public BaseGenerator {
|
||||
const std::string& full_type =
|
||||
(cpp_type
|
||||
? (IsVector(field.value.type)
|
||||
? "std::vector<" +
|
||||
? NativeVector(&field) + "<" +
|
||||
GenTypeNativePtr(cpp_type->constant, &field,
|
||||
false) +
|
||||
"> "
|
||||
@@ -3516,10 +3532,21 @@ class CppGenerator : public BaseGenerator {
|
||||
case BASE_TYPE_STRUCT: {
|
||||
if (IsStruct(type)) {
|
||||
const auto& struct_attrs = type.struct_def->attributes;
|
||||
const auto native_type = struct_attrs.Lookup("native_type");
|
||||
// Field-level native_type takes priority over struct-level
|
||||
// native_type
|
||||
auto field_native_type = afield.attributes.Lookup("native_type");
|
||||
const auto native_type = field_native_type
|
||||
? field_native_type
|
||||
: struct_attrs.Lookup("native_type");
|
||||
if (native_type) {
|
||||
std::string unpack_call = "::flatbuffers::UnPack";
|
||||
const auto pack_name = struct_attrs.Lookup("native_type_pack_name");
|
||||
// Field-level native_type_pack_name takes priority over
|
||||
// struct-level
|
||||
auto field_pack_name =
|
||||
afield.attributes.Lookup("native_type_pack_name");
|
||||
const auto pack_name =
|
||||
field_pack_name ? field_pack_name
|
||||
: struct_attrs.Lookup("native_type_pack_name");
|
||||
if (pack_name) {
|
||||
unpack_call += pack_name->constant;
|
||||
}
|
||||
@@ -3774,7 +3801,8 @@ class CppGenerator : public BaseGenerator {
|
||||
auto vector_type = field.value.type.VectorType();
|
||||
switch (vector_type.base_type) {
|
||||
case BASE_TYPE_STRING: {
|
||||
if (NativeString(&field) == "std::string") {
|
||||
if (NativeString(&field) == "std::string" &&
|
||||
NativeVector(&field) == "std::vector") {
|
||||
code += "_fbb.CreateVectorOfStrings(" + value + ")";
|
||||
} else {
|
||||
// Use by-function serialization to emulate
|
||||
@@ -3795,30 +3823,52 @@ class CppGenerator : public BaseGenerator {
|
||||
if (IsStruct(vector_type)) {
|
||||
const auto& struct_attrs =
|
||||
field.value.type.struct_def->attributes;
|
||||
const auto native_type = struct_attrs.Lookup("native_type");
|
||||
// Field-level native_type takes priority over struct-level
|
||||
// native_type
|
||||
auto field_native_type = field.attributes.Lookup("native_type");
|
||||
const auto native_type = field_native_type
|
||||
? field_native_type
|
||||
: struct_attrs.Lookup("native_type");
|
||||
if (native_type) {
|
||||
code += "_fbb.CreateVectorOfNativeStructs<";
|
||||
code += WrapInNameSpace(*vector_type.struct_def) + ", " +
|
||||
native_type->constant + ">";
|
||||
code += "(" + value;
|
||||
// Field-level native_type_pack_name takes priority over
|
||||
// struct-level
|
||||
auto field_pack_name =
|
||||
field.attributes.Lookup("native_type_pack_name");
|
||||
const auto pack_name =
|
||||
struct_attrs.Lookup("native_type_pack_name");
|
||||
field_pack_name
|
||||
? field_pack_name
|
||||
: struct_attrs.Lookup("native_type_pack_name");
|
||||
// Non-std vectors (e.g. eastl::vector) don't match the
|
||||
// std::vector overload, so use the pointer+size overload.
|
||||
const bool is_std_vec = NativeVector(&field) == "std::vector";
|
||||
if (is_std_vec) {
|
||||
code += "(" + value;
|
||||
} else {
|
||||
code += "(" + value + ".data(), " + value + ".size()";
|
||||
}
|
||||
if (pack_name) {
|
||||
code += ", ::flatbuffers::Pack" + pack_name->constant;
|
||||
}
|
||||
code += ")";
|
||||
} else {
|
||||
// If the field uses 64-bit addressing, create a 64-bit vector.
|
||||
const bool is_std_vec = NativeVector(&field) == "std::vector";
|
||||
const std::string vec_args =
|
||||
is_std_vec ? ("(" + value + ")")
|
||||
: ("(" + value + ".data(), " + value + ".size())");
|
||||
if (field.value.type.base_type == BASE_TYPE_VECTOR64) {
|
||||
code += "_fbb.CreateVectorOfStructs64";
|
||||
code += "_fbb.CreateVectorOfStructs64" + vec_args;
|
||||
} else {
|
||||
code += "_fbb.CreateVectorOfStructs";
|
||||
if (field.offset64) {
|
||||
// This is normal 32-bit vector, with 64-bit addressing.
|
||||
code += "64<::flatbuffers::Vector>";
|
||||
}
|
||||
code += vec_args;
|
||||
}
|
||||
code += "(" + value + ")";
|
||||
}
|
||||
} else {
|
||||
code += "_fbb.CreateVector<::flatbuffers::Offset<";
|
||||
@@ -3837,7 +3887,12 @@ class CppGenerator : public BaseGenerator {
|
||||
break;
|
||||
}
|
||||
case BASE_TYPE_BOOL: {
|
||||
code += "_fbb.CreateVector(" + value + ")";
|
||||
if (NativeVector(&field) == "std::vector") {
|
||||
code += "_fbb.CreateVector(" + value + ")";
|
||||
} else {
|
||||
code += "_fbb.CreateVector(" + value + ".data(), " + value +
|
||||
".size())";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BASE_TYPE_UNION: {
|
||||
@@ -3886,15 +3941,19 @@ class CppGenerator : public BaseGenerator {
|
||||
code += "; }, &_va )";
|
||||
} else {
|
||||
// If the field uses 64-bit addressing, create a 64-bit vector.
|
||||
const bool is_std_vec = NativeVector(&field) == "std::vector";
|
||||
const std::string vec_args =
|
||||
is_std_vec ? ("(" + value + ")")
|
||||
: ("(" + value + ".data(), " + value + ".size())");
|
||||
if (field.value.type.base_type == BASE_TYPE_VECTOR64) {
|
||||
code += "_fbb.CreateVector64(" + value + ")";
|
||||
code += "_fbb.CreateVector64" + vec_args;
|
||||
} else {
|
||||
code += "_fbb.CreateVector";
|
||||
if (field.offset64) {
|
||||
// This is normal 32-bit vector, with 64-bit addressing.
|
||||
code += "64<::flatbuffers::Vector>";
|
||||
}
|
||||
code += "(" + value + ")";
|
||||
code += vec_args;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -3918,11 +3977,22 @@ class CppGenerator : public BaseGenerator {
|
||||
case BASE_TYPE_STRUCT: {
|
||||
if (IsStruct(field.value.type)) {
|
||||
const auto& struct_attribs = field.value.type.struct_def->attributes;
|
||||
const auto native_type = struct_attribs.Lookup("native_type");
|
||||
// Field-level native_type takes priority over struct-level
|
||||
// native_type
|
||||
auto field_native_type = field.attributes.Lookup("native_type");
|
||||
const auto native_type = field_native_type
|
||||
? field_native_type
|
||||
: struct_attribs.Lookup("native_type");
|
||||
if (native_type && field.native_inline) {
|
||||
code += "::flatbuffers::Pack";
|
||||
// Field-level native_type_pack_name takes priority over
|
||||
// struct-level
|
||||
auto field_pack_name =
|
||||
field.attributes.Lookup("native_type_pack_name");
|
||||
const auto pack_name =
|
||||
struct_attribs.Lookup("native_type_pack_name");
|
||||
field_pack_name
|
||||
? field_pack_name
|
||||
: struct_attribs.Lookup("native_type_pack_name");
|
||||
if (pack_name) {
|
||||
code += pack_name->constant;
|
||||
}
|
||||
@@ -4086,9 +4156,15 @@ class CppGenerator : public BaseGenerator {
|
||||
bool check_ptr = false;
|
||||
if (field->value.type.base_type == BASE_TYPE_STRUCT) {
|
||||
if (IsStruct(field->value.type)) {
|
||||
// Field-level native_type takes priority over struct-level
|
||||
// native_type
|
||||
auto field_native_type =
|
||||
field->attributes.Lookup("native_type");
|
||||
auto native_type =
|
||||
field->value.type.struct_def->attributes.Lookup(
|
||||
"native_type");
|
||||
field_native_type
|
||||
? field_native_type
|
||||
: field->value.type.struct_def->attributes.Lookup(
|
||||
"native_type");
|
||||
auto native_inline = field->attributes.Lookup("native_inline");
|
||||
if (native_type) {
|
||||
pass_by_address = true;
|
||||
|
||||
@@ -1243,6 +1243,58 @@ class CSharpGenerator : public BaseGenerator {
|
||||
}
|
||||
code += " }\n";
|
||||
}
|
||||
|
||||
// Generate Length property and ByteBuffer accessor for arrays in structs.
|
||||
if (IsArray(field.value.type) && struct_def.fixed &&
|
||||
IsScalar(field.value.type.VectorType().base_type)) {
|
||||
auto camel_name = Name(field);
|
||||
if (camel_name == struct_def.name) { camel_name += "_"; }
|
||||
|
||||
// Generate Length constant
|
||||
code += " public const int " + camel_name;
|
||||
code += "Length = ";
|
||||
code += NumToString(field.value.type.fixed_length);
|
||||
code += ";\n";
|
||||
|
||||
// Generate GetBytes methods for scalar arrays (similar to vector pattern)
|
||||
code += "#if ENABLE_SPAN_T\n";
|
||||
code += " public Span<" + GenTypeBasic(field.value.type.VectorType()) +
|
||||
"> Get";
|
||||
code += camel_name;
|
||||
code += "Bytes() { return ";
|
||||
|
||||
// For byte arrays, we can return the span directly
|
||||
if (field.value.type.VectorType().base_type == BASE_TYPE_UCHAR) {
|
||||
code += "__p.bb.ToSpan(__p.bb_pos + ";
|
||||
code += NumToString(field.value.offset);
|
||||
code += ", ";
|
||||
code += NumToString(field.value.type.fixed_length *
|
||||
SizeOf(field.value.type.VectorType().base_type));
|
||||
code += ")";
|
||||
} else {
|
||||
// For other types, we need to cast the byte span
|
||||
code += "System.Runtime.InteropServices.MemoryMarshal.Cast<byte, " +
|
||||
GenTypeBasic(field.value.type.VectorType()) + ">(__p.bb.ToSpan(__p.bb_pos + ";
|
||||
code += NumToString(field.value.offset);
|
||||
code += ", ";
|
||||
code += NumToString(field.value.type.fixed_length *
|
||||
SizeOf(field.value.type.VectorType().base_type));
|
||||
code += "))";
|
||||
}
|
||||
code += "; }\n";
|
||||
code += "#else\n";
|
||||
code += " public ArraySegment<byte>? Get";
|
||||
code += camel_name;
|
||||
code += "Bytes() { return ";
|
||||
code += "__p.bb.ToArraySegment(__p.bb_pos + ";
|
||||
code += NumToString(field.value.offset);
|
||||
code += ", ";
|
||||
code += NumToString(field.value.type.fixed_length *
|
||||
SizeOf(field.value.type.VectorType().base_type));
|
||||
code += ");}\n";
|
||||
code += "#endif\n";
|
||||
}
|
||||
|
||||
// generate object accessors if is nested_flatbuffer
|
||||
if (field.nested_flatbuffer) {
|
||||
auto nested_type_name = NamespacedName(*field.nested_flatbuffer);
|
||||
|
||||
@@ -593,6 +593,18 @@ class PythonStubGenerator {
|
||||
"bytes) -> uoffset: ...\n";
|
||||
}
|
||||
}
|
||||
|
||||
stub << "def ";
|
||||
if (!parser_.opts.python_no_type_prefix_suffix) stub << type;
|
||||
stub << "Create" << namer_.Method(*field)
|
||||
<< "Vector(builder: flatbuffers.Builder, data: typing.Iterable["
|
||||
"typing.Any]) -> uoffset: ...\n";
|
||||
if (!parser_.opts.one_file &&
|
||||
!parser_.opts.python_no_type_prefix_suffix) {
|
||||
stub << "def Create" << namer_.Method(*field)
|
||||
<< "Vector(builder: flatbuffers.Builder, data: "
|
||||
"typing.Iterable[typing.Any]) -> uoffset: ...\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1467,6 +1479,59 @@ class PythonGenerator : public BaseGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
void BuildVectorCreationHelper(const StructDef& struct_def,
|
||||
const FieldDef& field, std::string* code_ptr,
|
||||
ImportMap& imports) const {
|
||||
auto& code = *code_ptr;
|
||||
const auto vector_type = field.value.type.VectorType();
|
||||
const bool is_struct_vector = IsStruct(vector_type);
|
||||
const bool is_scalar_vector =
|
||||
IsScalar(vector_type.base_type) || vector_type.enum_def != nullptr;
|
||||
const std::string struct_type = namer_.Type(struct_def);
|
||||
const std::string field_method = namer_.Method(field);
|
||||
const std::string helper_name =
|
||||
parser_.opts.python_no_type_prefix_suffix
|
||||
? "Create" + field_method + "Vector"
|
||||
: struct_type + "Create" + field_method + "Vector";
|
||||
|
||||
if (parser_.opts.python_typing) {
|
||||
imports.insert(ImportMapEntry{"typing", "Iterable"});
|
||||
code += "def " + helper_name +
|
||||
"(builder: flatbuffers.Builder, data: Iterable[Any]) -> int:\n";
|
||||
} else {
|
||||
code += "def " + helper_name + "(builder, data):\n";
|
||||
}
|
||||
|
||||
if (is_scalar_vector || is_struct_vector) {
|
||||
auto alignment = InlineAlignment(vector_type);
|
||||
auto elem_size = InlineSize(vector_type);
|
||||
code += Indent + "data = list(data)\n";
|
||||
code += Indent + "builder.StartVector(" + NumToString(elem_size) +
|
||||
", len(data), " + NumToString(alignment) + ")\n";
|
||||
code += Indent + "for item in reversed(data):\n";
|
||||
if (is_struct_vector) {
|
||||
code += Indent + Indent + "item.Pack(builder)\n";
|
||||
} else {
|
||||
code += Indent + Indent + "builder.Prepend" +
|
||||
namer_.Method(GenTypeBasic(vector_type)) + "(item)\n";
|
||||
}
|
||||
code += Indent + "return builder.EndVector()\n\n";
|
||||
} else {
|
||||
code += Indent + "return builder.CreateVectorOfTables(data)\n\n";
|
||||
}
|
||||
|
||||
if (!parser_.opts.one_file && !parser_.opts.python_no_type_prefix_suffix) {
|
||||
if (parser_.opts.python_typing) {
|
||||
code += "def Create" + field_method +
|
||||
"Vector(builder: flatbuffers.Builder, data: Iterable[Any]) "
|
||||
"-> int:\n";
|
||||
} else {
|
||||
code += "def Create" + field_method + "Vector(builder, data):\n";
|
||||
}
|
||||
code += Indent + helper_name + "(builder, data)\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Set the value of one of the members of a table's vector and fills in the
|
||||
// elements from a bytearray. This is for simplifying the use of nested
|
||||
// flatbuffers.
|
||||
@@ -1617,8 +1682,8 @@ class PythonGenerator : public BaseGenerator {
|
||||
}
|
||||
|
||||
// Generate table constructors, conditioned on its members' types.
|
||||
void GenTableBuilders(const StructDef& struct_def,
|
||||
std::string* code_ptr) const {
|
||||
void GenTableBuilders(const StructDef& struct_def, std::string* code_ptr,
|
||||
ImportMap& imports) const {
|
||||
GetStartOfTable(struct_def, code_ptr);
|
||||
|
||||
for (auto it = struct_def.fields.vec.begin();
|
||||
@@ -1630,6 +1695,7 @@ class PythonGenerator : public BaseGenerator {
|
||||
BuildFieldOfTable(struct_def, field, offset, code_ptr);
|
||||
if (IsVector(field.value.type)) {
|
||||
BuildVectorOfTable(struct_def, field, code_ptr);
|
||||
BuildVectorCreationHelper(struct_def, field, code_ptr, imports);
|
||||
BuildVectorOfTableFromBytes(struct_def, field, code_ptr);
|
||||
}
|
||||
}
|
||||
@@ -1696,7 +1762,7 @@ class PythonGenerator : public BaseGenerator {
|
||||
GenStructBuilder(struct_def, code_ptr);
|
||||
} else {
|
||||
// Creates a set of functions that allow table construction.
|
||||
GenTableBuilders(struct_def, code_ptr);
|
||||
GenTableBuilders(struct_def, code_ptr, imports);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -424,7 +424,6 @@ class RustGenerator : public BaseGenerator {
|
||||
code_.Clear();
|
||||
code_ += "// " + std::string(FlatBuffersGeneratedWarning());
|
||||
code_ += "// @generated";
|
||||
code_ += "extern crate alloc;";
|
||||
|
||||
assert(!cur_name_space_);
|
||||
|
||||
@@ -3006,6 +3005,7 @@ class RustGenerator : public BaseGenerator {
|
||||
"use self::serde::ser::{Serialize, Serializer, SerializeStruct};";
|
||||
code_ += "";
|
||||
}
|
||||
code_ += "extern crate alloc;";
|
||||
}
|
||||
|
||||
// Set up the correct namespace. This opens a namespace if the current
|
||||
|
||||
@@ -1963,7 +1963,7 @@ class SwiftGenerator : public BaseGenerator {
|
||||
std::string GenType(const Type& type,
|
||||
const bool should_consider_suffix = false) const {
|
||||
return IsScalar(type.base_type) ? GenTypeBasic(type)
|
||||
: IsArray(type) ? GenType(type.VectorType())
|
||||
: IsArray(type) ? GenType(type.VectorType())
|
||||
: GenTypePointer(type, should_consider_suffix);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ std::set<std::string> TypescriptKeywords() {
|
||||
"throw", "true", "try", "typeof", "var", "void",
|
||||
"while", "with", "as", "implements", "interface", "let",
|
||||
"package", "private", "protected", "public", "static", "yield",
|
||||
"undefined" // Used with --ts-undefined-for-optionals
|
||||
};
|
||||
}
|
||||
|
||||
@@ -111,7 +112,9 @@ class TsGenerator : public BaseGenerator {
|
||||
const std::string& file_name)
|
||||
: BaseGenerator(parser, path, file_name, "", "_", "ts"),
|
||||
namer_(WithFlagOptions(TypeScriptDefaultConfig(), parser.opts, path),
|
||||
TypescriptKeywords()) {}
|
||||
TypescriptKeywords()),
|
||||
null_keyword_(parser_.opts.ts_undefined_for_optionals ? "undefined"
|
||||
: "null") {}
|
||||
|
||||
bool generate() {
|
||||
generateEnums();
|
||||
@@ -215,6 +218,8 @@ class TsGenerator : public BaseGenerator {
|
||||
|
||||
std::map<std::string, NsDefinition> ns_defs_;
|
||||
|
||||
std::string null_keyword_;
|
||||
|
||||
// Generate code for all enums.
|
||||
void generateEnums() {
|
||||
for (auto it = parser_.enums_.vec.begin(); it != parser_.enums_.vec.end();
|
||||
@@ -468,7 +473,7 @@ class TsGenerator : public BaseGenerator {
|
||||
|
||||
std::string GenDefaultValue(const FieldDef& field, import_set& imports) {
|
||||
if (field.IsScalarOptional()) {
|
||||
return "null";
|
||||
return null_keyword_;
|
||||
}
|
||||
|
||||
const auto& value = field.value;
|
||||
@@ -519,7 +524,7 @@ class TsGenerator : public BaseGenerator {
|
||||
case BASE_TYPE_STRING:
|
||||
case BASE_TYPE_UNION:
|
||||
case BASE_TYPE_STRUCT: {
|
||||
return "null";
|
||||
return null_keyword_;
|
||||
}
|
||||
|
||||
case BASE_TYPE_ARRAY:
|
||||
@@ -555,16 +560,16 @@ class TsGenerator : public BaseGenerator {
|
||||
} else {
|
||||
name = AddImport(imports, owner, *type.struct_def).name;
|
||||
}
|
||||
return allowNull ? (name + "|null") : name;
|
||||
return allowNull ? (name + "|" + null_keyword_) : name;
|
||||
}
|
||||
}
|
||||
|
||||
switch (type.base_type) {
|
||||
case BASE_TYPE_BOOL:
|
||||
return allowNull ? "boolean|null" : "boolean";
|
||||
return allowNull ? ("boolean|" + null_keyword_) : "boolean";
|
||||
case BASE_TYPE_LONG:
|
||||
case BASE_TYPE_ULONG:
|
||||
return allowNull ? "bigint|null" : "bigint";
|
||||
return allowNull ? ("bigint|" + null_keyword_) : "bigint";
|
||||
case BASE_TYPE_ARRAY: {
|
||||
std::string name;
|
||||
if (type.element == BASE_TYPE_LONG || type.element == BASE_TYPE_ULONG) {
|
||||
@@ -579,16 +584,16 @@ class TsGenerator : public BaseGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
return name + (allowNull ? "|null" : "");
|
||||
return name + (allowNull ? ("|" + null_keyword_) : "");
|
||||
}
|
||||
default:
|
||||
if (IsScalar(type.base_type)) {
|
||||
if (type.enum_def) {
|
||||
const auto enum_name =
|
||||
AddImport(imports, owner, *type.enum_def).name;
|
||||
return allowNull ? (enum_name + "|null") : enum_name;
|
||||
return allowNull ? (enum_name + "|" + null_keyword_) : enum_name;
|
||||
}
|
||||
return allowNull ? "number|null" : "number";
|
||||
return allowNull ? ("number|" + null_keyword_) : "number";
|
||||
}
|
||||
return "flatbuffers.Offset";
|
||||
}
|
||||
@@ -1040,7 +1045,8 @@ class TsGenerator : public BaseGenerator {
|
||||
const auto& enum_def = *union_type.enum_def;
|
||||
|
||||
const auto valid_union_type = GenUnionTypeTS(enum_def, imports);
|
||||
const auto valid_union_type_with_null = valid_union_type + "|null";
|
||||
const auto valid_union_type_with_null =
|
||||
valid_union_type + "|" + null_keyword_;
|
||||
|
||||
auto ret = "\n\nexport function " + GenUnionConvFuncName(enum_def) +
|
||||
"(\n type: " + GetTypeName(enum_def) +
|
||||
@@ -1052,7 +1058,7 @@ class TsGenerator : public BaseGenerator {
|
||||
|
||||
const auto union_enum_loop = [&](const std::string& accessor_str) {
|
||||
ret += " switch(" + enum_type + "[type]) {\n";
|
||||
ret += " case 'NONE': return null; \n";
|
||||
ret += " case 'NONE': return " + null_keyword_ + "; \n";
|
||||
|
||||
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end();
|
||||
++it) {
|
||||
@@ -1076,7 +1082,7 @@ class TsGenerator : public BaseGenerator {
|
||||
ret += "\n";
|
||||
}
|
||||
|
||||
ret += " default: return null;\n";
|
||||
ret += " default: return " + null_keyword_ + ";\n";
|
||||
ret += " }\n";
|
||||
};
|
||||
|
||||
@@ -1121,7 +1127,8 @@ class TsGenerator : public BaseGenerator {
|
||||
ret += " const temp = " + conversion_function + "(this." +
|
||||
namer_.Method(field_name, "Type") + "(), " +
|
||||
field_binded_method + ");\n";
|
||||
ret += " if(temp === null) { return null; }\n";
|
||||
ret += " if(temp === " + null_keyword_ + ") { return " +
|
||||
null_keyword_ + "; }\n";
|
||||
ret += union_has_string
|
||||
? " if(typeof temp === 'string') { return temp; }\n"
|
||||
: "";
|
||||
@@ -1141,12 +1148,12 @@ class TsGenerator : public BaseGenerator {
|
||||
"++targetEnumIndex) {\n";
|
||||
ret += " const targetEnum = this." +
|
||||
namer_.Method(field_name, "Type") + "(targetEnumIndex);\n";
|
||||
ret += " if(targetEnum === null || " + enum_type +
|
||||
ret += " if(targetEnum === " + null_keyword_ + " || " + enum_type +
|
||||
"[targetEnum!] === 'NONE') { "
|
||||
"continue; }\n\n";
|
||||
ret += " const temp = " + conversion_function + "(targetEnum, " +
|
||||
field_binded_method + ", targetEnumIndex);\n";
|
||||
ret += " if(temp === null) { continue; }\n";
|
||||
ret += " if(temp === " + null_keyword_ + ") { continue; }\n";
|
||||
ret += union_has_string ? " if(typeof temp === 'string') { "
|
||||
"ret.push(temp); continue; }\n"
|
||||
: "";
|
||||
@@ -1163,11 +1170,11 @@ class TsGenerator : public BaseGenerator {
|
||||
return "";
|
||||
}
|
||||
|
||||
static std::string GenNullCheckConditional(
|
||||
const std::string& nullCheckVar, const std::string& trueVal,
|
||||
const std::string& falseVal = "null") {
|
||||
return "(" + nullCheckVar + " !== null ? " + trueVal + " : " + falseVal +
|
||||
")";
|
||||
std::string GenNullCheckConditional(const std::string& nullCheckVar,
|
||||
const std::string& trueVal,
|
||||
const std::string& falseVal) {
|
||||
return "(" + nullCheckVar + " !== " + null_keyword_ + " ? " + trueVal +
|
||||
" : " + falseVal + ")";
|
||||
}
|
||||
|
||||
std::string GenStructMemberValueTS(const StructDef& struct_def,
|
||||
@@ -1301,8 +1308,8 @@ class TsGenerator : public BaseGenerator {
|
||||
|
||||
const std::string field_accessor =
|
||||
"this." + namer_.Method(field) + "()";
|
||||
field_val = GenNullCheckConditional(field_accessor,
|
||||
field_accessor + "!.unpack()");
|
||||
field_val = GenNullCheckConditional(
|
||||
field_accessor, field_accessor + "!.unpack()", null_keyword_);
|
||||
auto packing = GenNullCheckConditional(
|
||||
"this." + field_field,
|
||||
"this." + field_field + "!.pack(builder)", "0");
|
||||
@@ -1510,8 +1517,8 @@ class TsGenerator : public BaseGenerator {
|
||||
break;
|
||||
}
|
||||
|
||||
// length 0 vector is simply empty instead of null
|
||||
field_type += is_vector ? "" : "|null";
|
||||
// length 0 vector is simply empty instead of null/undefined.
|
||||
field_type += is_vector ? "" : ("|" + null_keyword_);
|
||||
}
|
||||
|
||||
if (!field_offset_decl.empty()) {
|
||||
@@ -1540,7 +1547,7 @@ class TsGenerator : public BaseGenerator {
|
||||
} else {
|
||||
if (field.IsScalarOptional()) {
|
||||
pack_func_create_call +=
|
||||
" if (" + field_offset_val + " !== null)\n ";
|
||||
" if (" + field_offset_val + " !== " + null_keyword_ + ")\n ";
|
||||
}
|
||||
pack_func_create_call += " " + struct_name + "." +
|
||||
namer_.Method("add", field) + "(builder, " +
|
||||
@@ -1630,7 +1637,8 @@ class TsGenerator : public BaseGenerator {
|
||||
"> {\n";
|
||||
else
|
||||
code += " {\n";
|
||||
code += " bb: flatbuffers.ByteBuffer|null = null;\n";
|
||||
code += " bb: flatbuffers.ByteBuffer|" + null_keyword_ + " = " +
|
||||
null_keyword_ + ";\n";
|
||||
code += " bb_pos = 0;\n";
|
||||
|
||||
// Generate the __init method that sets the field in a pre-existing
|
||||
@@ -1682,7 +1690,7 @@ class TsGenerator : public BaseGenerator {
|
||||
GenDocComment(field.doc_comment, code_ptr);
|
||||
std::string prefix = namer_.Method(field) + "(";
|
||||
if (is_string) {
|
||||
code += prefix + "):string|null\n";
|
||||
code += prefix + "):string|" + null_keyword_ + "\n";
|
||||
code +=
|
||||
prefix + "optionalEncoding:flatbuffers.Encoding" + "):" +
|
||||
GenTypeName(imports, struct_def, field.value.type, false, true) +
|
||||
@@ -1732,7 +1740,8 @@ class TsGenerator : public BaseGenerator {
|
||||
.name;
|
||||
GenDocComment(field.doc_comment, code_ptr);
|
||||
code += namer_.Method(field);
|
||||
code += "(obj?:" + type + "):" + type + "|null {\n";
|
||||
code +=
|
||||
"(obj?:" + type + "):" + type + "|" + null_keyword_ + " {\n";
|
||||
|
||||
if (struct_def.fixed) {
|
||||
code += " return (obj || " + GenerateNewExpression(type);
|
||||
@@ -1745,7 +1754,7 @@ class TsGenerator : public BaseGenerator {
|
||||
code += field.value.type.struct_def->fixed
|
||||
? "this.bb_pos + offset"
|
||||
: GenBBAccess() + ".__indirect(this.bb_pos + offset)";
|
||||
code += ", " + GenBBAccess() + ") : null;\n";
|
||||
code += ", " + GenBBAccess() + ") : " + null_keyword_ + ";\n";
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -1798,7 +1807,7 @@ class TsGenerator : public BaseGenerator {
|
||||
} else {
|
||||
code += prefix;
|
||||
}
|
||||
code += "):" + vectortypename + "|null {\n";
|
||||
code += "):" + vectortypename + "|" + null_keyword_ + " {\n";
|
||||
|
||||
if (vectortype.base_type == BASE_TYPE_STRUCT) {
|
||||
code += offset_prefix + "(obj || " +
|
||||
@@ -1838,7 +1847,7 @@ class TsGenerator : public BaseGenerator {
|
||||
code += " : 0";
|
||||
}
|
||||
} else {
|
||||
code += ": null";
|
||||
code += ": " + null_keyword_;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1896,7 +1905,7 @@ class TsGenerator : public BaseGenerator {
|
||||
} else {
|
||||
code += prefix;
|
||||
}
|
||||
code += "):" + vectortypename + "|null {\n";
|
||||
code += "):" + vectortypename + "|" + null_keyword_ + " {\n";
|
||||
|
||||
if (vectortype.base_type == BASE_TYPE_STRUCT) {
|
||||
code += offset_prefix + "(obj || " +
|
||||
@@ -1922,12 +1931,12 @@ class TsGenerator : public BaseGenerator {
|
||||
code += "BigInt(0)";
|
||||
} else if (IsScalar(field.value.type.element)) {
|
||||
if (field.value.type.enum_def) {
|
||||
code += "null";
|
||||
code += null_keyword_;
|
||||
} else {
|
||||
code += "0";
|
||||
}
|
||||
} else {
|
||||
code += "null";
|
||||
code += null_keyword_;
|
||||
}
|
||||
code += ";\n";
|
||||
break;
|
||||
@@ -1940,13 +1949,13 @@ class TsGenerator : public BaseGenerator {
|
||||
const auto& union_enum = *(field.value.type.enum_def);
|
||||
const auto union_type = GenUnionGenericTypeTS(union_enum);
|
||||
code += "<T extends flatbuffers.Table>(obj:" + union_type +
|
||||
"):" + union_type +
|
||||
"|null "
|
||||
"):" + union_type + "|" + null_keyword_ +
|
||||
" "
|
||||
"{\n";
|
||||
|
||||
code += offset_prefix +
|
||||
GenGetter(field.value.type, "(obj, this.bb_pos + offset)") +
|
||||
" : null;\n";
|
||||
" : " + null_keyword_ + ";\n";
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -2008,14 +2017,15 @@ class TsGenerator : public BaseGenerator {
|
||||
GenDocComment(code_ptr);
|
||||
|
||||
code += namer_.Method(field, "Array");
|
||||
code +=
|
||||
"():" + GenType(vectorType) + "Array|null {\n" + offset_prefix;
|
||||
code += "():" + GenType(vectorType) + "Array|" + null_keyword_ +
|
||||
" {\n" + offset_prefix;
|
||||
|
||||
code += "new " + GenType(vectorType) + "Array(" + GenBBAccess() +
|
||||
".bytes().buffer, " + GenBBAccess() +
|
||||
".bytes().byteOffset + " + GenBBAccess() +
|
||||
".__vector(this.bb_pos + offset), " + GenBBAccess() +
|
||||
".__vector_len(this.bb_pos + offset)) : null;\n}\n\n";
|
||||
".__vector_len(this.bb_pos + offset)) : " + null_keyword_ +
|
||||
";\n}\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2085,7 +2095,7 @@ class TsGenerator : public BaseGenerator {
|
||||
if (!IsScalar(field.value.type.base_type)) {
|
||||
code += "0";
|
||||
} else if (HasNullDefault(field)) {
|
||||
code += "null";
|
||||
code += null_keyword_;
|
||||
} else {
|
||||
if (field.value.type.base_type == BASE_TYPE_BOOL) {
|
||||
code += "+";
|
||||
@@ -2202,7 +2212,7 @@ class TsGenerator : public BaseGenerator {
|
||||
const auto arg_name = GetArgName(field);
|
||||
|
||||
if (field.IsScalarOptional()) {
|
||||
code += " if (" + arg_name + " !== null)\n ";
|
||||
code += " if (" + arg_name + " !== " + null_keyword_ + ")\n ";
|
||||
}
|
||||
|
||||
code += " " + methodPrefix + "." + namer_.Method("add", field) + "(";
|
||||
@@ -2242,7 +2252,7 @@ class TsGenerator : public BaseGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
static bool HasNullDefault(const FieldDef& field) {
|
||||
bool HasNullDefault(const FieldDef& field) {
|
||||
return field.IsOptional() && field.value.constant == "null";
|
||||
}
|
||||
|
||||
|
||||
@@ -2755,6 +2755,42 @@ std::vector<IncludedFile> Parser::GetIncludedFiles() const {
|
||||
return {it->second.cbegin(), it->second.cend()};
|
||||
}
|
||||
|
||||
bool Parser::HasCircularStructDependency() {
|
||||
std::function<bool(StructDef*)> visit =
|
||||
[&](StructDef* struct_def) {
|
||||
// Only consider fixed structs and structs we have yet to check
|
||||
if (!struct_def->fixed || struct_def->cycle_status == StructDef::CycleStatus::Checked) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (struct_def->cycle_status == StructDef::CycleStatus::InProgress) {
|
||||
// cycle found
|
||||
return true;
|
||||
}
|
||||
|
||||
struct_def->cycle_status = StructDef::CycleStatus::InProgress;
|
||||
|
||||
for (const auto& field : struct_def->fields.vec) {
|
||||
if (field->value.type.base_type == BASE_TYPE_STRUCT) {
|
||||
if (visit(field->value.type.struct_def)) {
|
||||
return true; // Cycle detected in recursion.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct_def->cycle_status = StructDef::CycleStatus::Checked;
|
||||
return false; // No cycle detected.
|
||||
};
|
||||
|
||||
for (const auto& struct_def : structs_.vec) {
|
||||
if (visit(struct_def)) {
|
||||
return true; // Cycle detected.
|
||||
}
|
||||
}
|
||||
|
||||
return false; // No cycle detected.
|
||||
}
|
||||
|
||||
bool Parser::SupportsOptionalScalars(const flatbuffers::IDLOptions& opts) {
|
||||
static FLATBUFFERS_CONSTEXPR unsigned long supported_langs =
|
||||
IDLOptions::kRust | IDLOptions::kSwift | IDLOptions::kLobster |
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Copyright 2014 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -90,6 +90,9 @@ namespace Google.FlatBuffers.Test
|
||||
fbb.AddOffset(test1.Value);
|
||||
var testArrayOfString = fbb.EndVector();
|
||||
|
||||
var longsVector = Monster.CreateVectorOfLongsVector(fbb, new long[] { 1, 100, 10000, 1000000, 100000000 });
|
||||
var doublesVector = Monster.CreateVectorOfDoublesVector(fbb, new double[] { -1.7976931348623157e+308, 0, 1.7976931348623157e+308 });
|
||||
|
||||
Monster.StartMonster(fbb);
|
||||
Monster.AddPos(fbb, Vec3.CreateVec3(fbb, 1.0f, 2.0f, 3.0f, 3.0,
|
||||
Color.Green, (short)5, (sbyte)6));
|
||||
@@ -102,6 +105,8 @@ namespace Google.FlatBuffers.Test
|
||||
Monster.AddTestarrayofstring(fbb, testArrayOfString);
|
||||
Monster.AddTestbool(fbb, true);
|
||||
Monster.AddTestarrayoftables(fbb, sortMons);
|
||||
Monster.AddVectorOfLongs(fbb, longsVector);
|
||||
Monster.AddVectorOfDoubles(fbb, doublesVector);
|
||||
var mon = Monster.EndMonster(fbb);
|
||||
|
||||
if (sizePrefix)
|
||||
@@ -285,6 +290,13 @@ namespace Google.FlatBuffers.Test
|
||||
Assert.IsTrue(monster.GetTestarrayofboolsBytes().HasValue);
|
||||
}
|
||||
#endif
|
||||
|
||||
var longArray = monster.GetVectorOfLongsArray();
|
||||
Assert.AreEqual(5, longArray.Length);
|
||||
Assert.AreEqual(100, longArray[1]);
|
||||
|
||||
var doublesArray = monster.GetVectorOfDoublesArray();
|
||||
Assert.AreEqual(3, doublesArray.Length);
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
|
||||
249
tests/FlatBuffers.Test/FlatBuffersFixedLengthArrayTests.cs
Normal file
249
tests/FlatBuffers.Test/FlatBuffersFixedLengthArrayTests.cs
Normal file
@@ -0,0 +1,249 @@
|
||||
/*
|
||||
* Copyright 2025 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.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using MyGame.Example;
|
||||
|
||||
namespace Google.FlatBuffers.Test
|
||||
{
|
||||
[FlatBuffersTestClass]
|
||||
public class FlatBuffersFixedLengthArrayTests
|
||||
{
|
||||
[FlatBuffersTestMethod]
|
||||
public void FixedLengthArray_LengthConstantsMatchSchema_ReturnTrue()
|
||||
{
|
||||
const int nestedALength = NestedStruct.ALength;
|
||||
const int nestedCLength = NestedStruct.CLength;
|
||||
const int nestedDLength = NestedStruct.DLength;
|
||||
const int arrayBLength = ArrayStruct.BLength;
|
||||
const int arrayFLength = ArrayStruct.FLength;
|
||||
|
||||
Assert.AreEqual(2, nestedALength);
|
||||
Assert.AreEqual(2, nestedCLength);
|
||||
Assert.AreEqual(2, nestedDLength);
|
||||
Assert.AreEqual(15, arrayBLength);
|
||||
Assert.AreEqual(2, arrayFLength);
|
||||
}
|
||||
|
||||
#if ENABLE_SPAN_T
|
||||
[FlatBuffersTestMethod]
|
||||
public void FixedLengthArray_GetBytesSpanLengthIsCorrect_ReturnTrue()
|
||||
{
|
||||
var builder = new FlatBufferBuilder(1024);
|
||||
var ints = new int[] { 1, 2 };
|
||||
var enumB = TestEnum.A;
|
||||
var enums = new TestEnum[] { TestEnum.B, TestEnum.C };
|
||||
var longs = new long[] { 10L, 20L };
|
||||
|
||||
var structOffset = NestedStruct.CreateNestedStruct(builder, ints, enumB, enums, longs);
|
||||
builder.Finish(structOffset.Value);
|
||||
|
||||
var bb = builder.DataBuffer;
|
||||
var nestedStruct = new NestedStruct();
|
||||
nestedStruct.__assign(bb.Length - builder.Offset, bb);
|
||||
|
||||
Span<int> intSpan = nestedStruct.GetABytes();
|
||||
Span<TestEnum> enumSpan = nestedStruct.GetCBytes();
|
||||
Span<long> longSpan = nestedStruct.GetDBytes();
|
||||
|
||||
Assert.AreEqual(intSpan.Length, NestedStruct.ALength);
|
||||
Assert.AreEqual(enumSpan.Length, NestedStruct.CLength);
|
||||
Assert.AreEqual(longSpan.Length, NestedStruct.DLength);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !ENABLE_SPAN_T
|
||||
[FlatBuffersTestMethod]
|
||||
public void FixedLengthArray_GetBytesArraySegmentLengthIsCorrect_ReturnTrue()
|
||||
{
|
||||
var builder = new FlatBufferBuilder(1024);
|
||||
var ints = new int[] { 1, 2 };
|
||||
var enumB = TestEnum.A;
|
||||
var enums = new TestEnum[] { TestEnum.B, TestEnum.C };
|
||||
var longs = new long[] { 10L, 20L };
|
||||
|
||||
var structOffset = NestedStruct.CreateNestedStruct(builder, ints, enumB, enums, longs);
|
||||
builder.Finish(structOffset.Value);
|
||||
|
||||
var buffer = builder.DataBuffer;
|
||||
var nestedStruct = new NestedStruct();
|
||||
nestedStruct.__assign(buffer.Length - builder.Offset, buffer);
|
||||
|
||||
Assert.IsTrue(nestedStruct.GetABytes().HasValue);
|
||||
Assert.IsTrue(nestedStruct.GetCBytes().HasValue);
|
||||
Assert.IsTrue(nestedStruct.GetDBytes().HasValue);
|
||||
|
||||
ArraySegment<byte> intSegment = nestedStruct.GetABytes().Value;
|
||||
ArraySegment<byte> enumSegment = nestedStruct.GetCBytes().Value;
|
||||
ArraySegment<byte> longSegment = nestedStruct.GetDBytes().Value;
|
||||
|
||||
Assert.AreEqual(intSegment.Count, NestedStruct.ALength * sizeof(int));
|
||||
Assert.AreEqual(enumSegment.Count, NestedStruct.CLength * sizeof(sbyte));
|
||||
Assert.AreEqual(longSegment.Count, NestedStruct.DLength * sizeof(long));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_SPAN_T
|
||||
[FlatBuffersTestMethod]
|
||||
public void FixedLengthArray_GetBytesSpanEquality_ReturnTrue()
|
||||
{
|
||||
var builder = new FlatBufferBuilder(1024);
|
||||
|
||||
var floatA = 3.14f;
|
||||
var intArray = Enumerable.Range(1, 15).ToArray();
|
||||
var byteC = (sbyte)42;
|
||||
var intE = 999;
|
||||
var longArray = new long[] { 5000L, 6000L };
|
||||
|
||||
var nestedInts = new int[2, 2] { { 10, 20 }, { 30, 40 } };
|
||||
var nestedEnumB = new TestEnum[] { TestEnum.A, TestEnum.B };
|
||||
var nestedEnums = new TestEnum[2, 2] { { TestEnum.A, TestEnum.B }, { TestEnum.C, TestEnum.A } };
|
||||
var nestedLongs = new long[2, 2] { { 100L, 200L }, { 300L, 400L } };
|
||||
|
||||
var structOffset = ArrayStruct.CreateArrayStruct(builder, floatA, intArray, byteC,
|
||||
nestedInts, nestedEnumB, nestedEnums, nestedLongs, intE, longArray);
|
||||
|
||||
ArrayTable.StartArrayTable(builder);
|
||||
ArrayTable.AddA(builder, structOffset);
|
||||
var rootTable = ArrayTable.EndArrayTable(builder);
|
||||
builder.Finish(rootTable.Value);
|
||||
|
||||
var finishedBytes = builder.SizedByteArray();
|
||||
ByteBuffer bb = new ByteBuffer(finishedBytes);
|
||||
ArrayTable arrayTable = ArrayTable.GetRootAsArrayTable(bb);
|
||||
ArrayStruct arrayStruct = arrayTable.A.Value;
|
||||
|
||||
Assert.AreEqual(byteC, arrayStruct.C);
|
||||
Assert.AreEqual(intE, arrayStruct.E);
|
||||
|
||||
Assert.IsTrue(arrayStruct.GetBBytes().SequenceEqual(intArray));
|
||||
Assert.IsTrue(arrayStruct.GetFBytes().SequenceEqual(longArray));
|
||||
|
||||
// Test nested struct arrays
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
var nestedStruct = arrayStruct.D(i);
|
||||
|
||||
var nestedIntSpan = nestedStruct.GetABytes();
|
||||
var expectedNestedInts = new int[] { nestedInts[i, 0], nestedInts[i, 1] };
|
||||
Assert.IsTrue(nestedIntSpan.SequenceEqual(expectedNestedInts));
|
||||
|
||||
Assert.AreEqual(nestedEnumB[i], nestedStruct.B);
|
||||
|
||||
var nestedEnumSpan = nestedStruct.GetCBytes();
|
||||
var expectedNestedEnums = new TestEnum[] { nestedEnums[i, 0], nestedEnums[i, 1] };
|
||||
Assert.IsTrue(nestedEnumSpan.SequenceEqual(expectedNestedEnums));
|
||||
|
||||
var nestedLongSpan = nestedStruct.GetDBytes();
|
||||
var expectedNestedLongs = new long[] { nestedLongs[i, 0], nestedLongs[i, 1] };
|
||||
Assert.IsTrue(nestedLongSpan.SequenceEqual(expectedNestedLongs));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !ENABLE_SPAN_T
|
||||
[FlatBuffersTestMethod]
|
||||
public void FixedLengthArray_GetBytesArraySegmentEquality_ReturnTrue()
|
||||
{
|
||||
var builder = new FlatBufferBuilder(1024);
|
||||
|
||||
var floatA = 3.14f;
|
||||
var intArray = Enumerable.Range(1, 15).ToArray();
|
||||
var byteC = (sbyte)42;
|
||||
var intE = 999;
|
||||
var longArray = new long[] { 5000L, 6000L };
|
||||
|
||||
var nestedInts = new int[2, 2] { { 10, 20 }, { 30, 40 } };
|
||||
var nestedEnumB = new TestEnum[] { TestEnum.A, TestEnum.B };
|
||||
var nestedEnums = new TestEnum[2, 2] { { TestEnum.A, TestEnum.B }, { TestEnum.C, TestEnum.A } };
|
||||
var nestedLongs = new long[2, 2] { { 100L, 200L }, { 300L, 400L } };
|
||||
|
||||
var structOffset = ArrayStruct.CreateArrayStruct(builder, floatA, intArray, byteC,
|
||||
nestedInts, nestedEnumB, nestedEnums, nestedLongs, intE, longArray);
|
||||
|
||||
ArrayTable.StartArrayTable(builder);
|
||||
ArrayTable.AddA(builder, structOffset);
|
||||
var rootTable = ArrayTable.EndArrayTable(builder);
|
||||
builder.Finish(rootTable.Value);
|
||||
|
||||
var finishedBytes = builder.SizedByteArray();
|
||||
ByteBuffer bb = new ByteBuffer(finishedBytes);
|
||||
ArrayTable arrayTable = ArrayTable.GetRootAsArrayTable(bb);
|
||||
ArrayStruct arrayStruct = arrayTable.A.Value;
|
||||
|
||||
// Test that we can read basic scalars correctly
|
||||
Assert.AreEqual(byteC, arrayStruct.C);
|
||||
Assert.AreEqual(intE, arrayStruct.E);
|
||||
|
||||
Assert.IsTrue(arrayStruct.GetBBytes().HasValue);
|
||||
var intSegment = arrayStruct.GetBBytes().Value;
|
||||
for (int i = 0, offset = 0; i < intArray.Length; i++, offset += sizeof(int))
|
||||
{
|
||||
var segmentValue = BitConverter.ToInt32(intSegment.Array,
|
||||
intSegment.Offset + offset);
|
||||
Assert.AreEqual(intArray[i], segmentValue);
|
||||
}
|
||||
|
||||
Assert.IsTrue(arrayStruct.GetFBytes().HasValue);
|
||||
var longSegment = arrayStruct.GetFBytes().Value;
|
||||
for (int i = 0, offset = 0; i < longArray.Length; i++, offset += sizeof(long))
|
||||
{
|
||||
var segmentValue = BitConverter.ToInt64(longSegment.Array,
|
||||
longSegment.Offset + offset);
|
||||
Assert.AreEqual(longArray[i], segmentValue);
|
||||
}
|
||||
|
||||
// Test nested struct arrays
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
var nestedStruct = arrayStruct.D(i);
|
||||
|
||||
Assert.IsTrue(nestedStruct.GetABytes().HasValue);
|
||||
var nestedIntSegment = nestedStruct.GetABytes().Value;
|
||||
var expectedNestedInts = new int[] { nestedInts[i, 0], nestedInts[i, 1] };
|
||||
for (int ii = 0, offset = 0; ii < NestedStruct.ALength; ii++, offset += sizeof(int))
|
||||
{
|
||||
var segmentValue = BitConverter.ToInt32(nestedIntSegment.Array,
|
||||
nestedIntSegment.Offset + offset);
|
||||
Assert.AreEqual(expectedNestedInts[ii], segmentValue);
|
||||
}
|
||||
|
||||
Assert.AreEqual(nestedEnumB[i], nestedStruct.B);
|
||||
|
||||
Assert.IsTrue(nestedStruct.GetCBytes().HasValue);
|
||||
var nestedEnumSegment = nestedStruct.GetCBytes().Value;
|
||||
var expectedNestedEnums = new TestEnum[] { nestedEnums[i, 0], nestedEnums[i, 1] };
|
||||
for (int ii = 0, offset = 0; ii < NestedStruct.CLength; ii++, offset += sizeof(sbyte))
|
||||
{
|
||||
var segmentValue = (TestEnum)nestedEnumSegment.Array[nestedEnumSegment.Offset + offset];
|
||||
Assert.AreEqual(expectedNestedEnums[ii], segmentValue);
|
||||
}
|
||||
|
||||
Assert.IsTrue(nestedStruct.GetDBytes().HasValue);
|
||||
var nestedLongSegment = nestedStruct.GetDBytes().Value;
|
||||
var expectedNestedLongs = new long[] { nestedLongs[i, 0], nestedLongs[i, 1] };
|
||||
for (int ii = 0, offset = 0; ii < NestedStruct.DLength; ii++, offset += sizeof(long))
|
||||
{
|
||||
var segmentValue = BitConverter.ToInt64(nestedLongSegment.Array,
|
||||
nestedLongSegment.Offset + offset);
|
||||
Assert.AreEqual(expectedNestedLongs[ii], segmentValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,12 @@ public struct ArrayStruct : IFlatbufferObject
|
||||
public float A { get { return __p.bb.GetFloat(__p.bb_pos + 0); } }
|
||||
public void MutateA(float a) { __p.bb.PutFloat(__p.bb_pos + 0, a); }
|
||||
public int B(int j) { return __p.bb.GetInt(__p.bb_pos + 4 + j * 4); }
|
||||
public const int BLength = 15;
|
||||
#if ENABLE_SPAN_T
|
||||
public Span<int> GetBBytes() { return System.Runtime.InteropServices.MemoryMarshal.Cast<byte, int>(__p.bb.ToSpan(__p.bb_pos + 4, 60)); }
|
||||
#else
|
||||
public ArraySegment<byte>? GetBBytes() { return __p.bb.ToArraySegment(__p.bb_pos + 4, 60);}
|
||||
#endif
|
||||
public void MutateB(int j, int b) { __p.bb.PutInt(__p.bb_pos + 4 + j * 4, b); }
|
||||
public sbyte C { get { return __p.bb.GetSbyte(__p.bb_pos + 64); } }
|
||||
public void MutateC(sbyte c) { __p.bb.PutSbyte(__p.bb_pos + 64, c); }
|
||||
@@ -26,6 +32,12 @@ public struct ArrayStruct : IFlatbufferObject
|
||||
public int E { get { return __p.bb.GetInt(__p.bb_pos + 136); } }
|
||||
public void MutateE(int e) { __p.bb.PutInt(__p.bb_pos + 136, e); }
|
||||
public long F(int j) { return __p.bb.GetLong(__p.bb_pos + 144 + j * 8); }
|
||||
public const int FLength = 2;
|
||||
#if ENABLE_SPAN_T
|
||||
public Span<long> GetFBytes() { return System.Runtime.InteropServices.MemoryMarshal.Cast<byte, long>(__p.bb.ToSpan(__p.bb_pos + 144, 16)); }
|
||||
#else
|
||||
public ArraySegment<byte>? GetFBytes() { return __p.bb.ToArraySegment(__p.bb_pos + 144, 16);}
|
||||
#endif
|
||||
public void MutateF(int j, long f) { __p.bb.PutLong(__p.bb_pos + 144 + j * 8, f); }
|
||||
|
||||
public static Offset<MyGame.Example.ArrayStruct> CreateArrayStruct(FlatBufferBuilder builder, float A, int[] B, sbyte C, int[,] d_A, MyGame.Example.TestEnum[] d_B, MyGame.Example.TestEnum[,] d_C, long[,] d_D, int E, long[] F) {
|
||||
|
||||
@@ -28,6 +28,8 @@ function Monster.New()
|
||||
return o
|
||||
end
|
||||
|
||||
local FileIdentifier = "MONS"
|
||||
|
||||
function Monster.GetRootAsMonster(buf, offset)
|
||||
if type(buf) == "string" then
|
||||
buf = flatbuffers.binaryArray.New(buf)
|
||||
@@ -1099,4 +1101,12 @@ function Monster.End(builder)
|
||||
return builder:EndObject()
|
||||
end
|
||||
|
||||
function Monster.FinishMonsterBuffer(builder, offset)
|
||||
builder:FinishWithIdentifier(offset, FileIdentifier)
|
||||
end
|
||||
|
||||
function Monster.FinishSizePrefixedMonsterBuffer(builder, offset)
|
||||
builder:FinishSizePrefixedWithIdentifier(offset, FileIdentifier)
|
||||
end
|
||||
|
||||
return Monster
|
||||
@@ -914,6 +914,16 @@ def MonsterStartInventoryVector(builder, numElems):
|
||||
def StartInventoryVector(builder, numElems):
|
||||
return MonsterStartInventoryVector(builder, numElems)
|
||||
|
||||
def MonsterCreateInventoryVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(1, len(data), 1)
|
||||
for item in reversed(data):
|
||||
builder.PrependUint8(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateInventoryVector(builder, data):
|
||||
MonsterCreateInventoryVector(builder, data)
|
||||
|
||||
def MonsterAddColor(builder, color):
|
||||
builder.PrependUint8Slot(6, color, 8)
|
||||
|
||||
@@ -944,6 +954,16 @@ def MonsterStartTest4Vector(builder, numElems):
|
||||
def StartTest4Vector(builder, numElems):
|
||||
return MonsterStartTest4Vector(builder, numElems)
|
||||
|
||||
def MonsterCreateTest4Vector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(4, len(data), 2)
|
||||
for item in reversed(data):
|
||||
item.Pack(builder)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateTest4Vector(builder, data):
|
||||
MonsterCreateTest4Vector(builder, data)
|
||||
|
||||
def MonsterAddTestarrayofstring(builder, testarrayofstring):
|
||||
builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring), 0)
|
||||
|
||||
@@ -956,6 +976,12 @@ def MonsterStartTestarrayofstringVector(builder, numElems):
|
||||
def StartTestarrayofstringVector(builder, numElems):
|
||||
return MonsterStartTestarrayofstringVector(builder, numElems)
|
||||
|
||||
def MonsterCreateTestarrayofstringVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateTestarrayofstringVector(builder, data):
|
||||
MonsterCreateTestarrayofstringVector(builder, data)
|
||||
|
||||
def MonsterAddTestarrayoftables(builder, testarrayoftables):
|
||||
builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayoftables), 0)
|
||||
|
||||
@@ -968,6 +994,12 @@ def MonsterStartTestarrayoftablesVector(builder, numElems):
|
||||
def StartTestarrayoftablesVector(builder, numElems):
|
||||
return MonsterStartTestarrayoftablesVector(builder, numElems)
|
||||
|
||||
def MonsterCreateTestarrayoftablesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateTestarrayoftablesVector(builder, data):
|
||||
MonsterCreateTestarrayoftablesVector(builder, data)
|
||||
|
||||
def MonsterAddEnemy(builder, enemy):
|
||||
builder.PrependUOffsetTRelativeSlot(12, flatbuffers.number_types.UOffsetTFlags.py_type(enemy), 0)
|
||||
|
||||
@@ -986,6 +1018,16 @@ def MonsterStartTestnestedflatbufferVector(builder, numElems):
|
||||
def StartTestnestedflatbufferVector(builder, numElems):
|
||||
return MonsterStartTestnestedflatbufferVector(builder, numElems)
|
||||
|
||||
def MonsterCreateTestnestedflatbufferVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(1, len(data), 1)
|
||||
for item in reversed(data):
|
||||
builder.PrependUint8(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateTestnestedflatbufferVector(builder, data):
|
||||
MonsterCreateTestnestedflatbufferVector(builder, data)
|
||||
|
||||
def MonsterMakeTestnestedflatbufferVectorFromBytes(builder, bytes):
|
||||
builder.StartVector(1, len(bytes), 1)
|
||||
builder.head = builder.head - len(bytes)
|
||||
@@ -1065,6 +1107,16 @@ def MonsterStartTestarrayofboolsVector(builder, numElems):
|
||||
def StartTestarrayofboolsVector(builder, numElems):
|
||||
return MonsterStartTestarrayofboolsVector(builder, numElems)
|
||||
|
||||
def MonsterCreateTestarrayofboolsVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(1, len(data), 1)
|
||||
for item in reversed(data):
|
||||
builder.PrependBool(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateTestarrayofboolsVector(builder, data):
|
||||
MonsterCreateTestarrayofboolsVector(builder, data)
|
||||
|
||||
def MonsterAddTestf(builder, testf):
|
||||
builder.PrependFloat32Slot(25, testf, 3.14159)
|
||||
|
||||
@@ -1095,6 +1147,12 @@ def MonsterStartTestarrayofstring2Vector(builder, numElems):
|
||||
def StartTestarrayofstring2Vector(builder, numElems):
|
||||
return MonsterStartTestarrayofstring2Vector(builder, numElems)
|
||||
|
||||
def MonsterCreateTestarrayofstring2Vector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateTestarrayofstring2Vector(builder, data):
|
||||
MonsterCreateTestarrayofstring2Vector(builder, data)
|
||||
|
||||
def MonsterAddTestarrayofsortedstruct(builder, testarrayofsortedstruct):
|
||||
builder.PrependUOffsetTRelativeSlot(29, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofsortedstruct), 0)
|
||||
|
||||
@@ -1107,6 +1165,16 @@ def MonsterStartTestarrayofsortedstructVector(builder, numElems):
|
||||
def StartTestarrayofsortedstructVector(builder, numElems):
|
||||
return MonsterStartTestarrayofsortedstructVector(builder, numElems)
|
||||
|
||||
def MonsterCreateTestarrayofsortedstructVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(8, len(data), 4)
|
||||
for item in reversed(data):
|
||||
item.Pack(builder)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateTestarrayofsortedstructVector(builder, data):
|
||||
MonsterCreateTestarrayofsortedstructVector(builder, data)
|
||||
|
||||
def MonsterAddFlex(builder, flex):
|
||||
builder.PrependUOffsetTRelativeSlot(30, flatbuffers.number_types.UOffsetTFlags.py_type(flex), 0)
|
||||
|
||||
@@ -1119,6 +1187,16 @@ def MonsterStartFlexVector(builder, numElems):
|
||||
def StartFlexVector(builder, numElems):
|
||||
return MonsterStartFlexVector(builder, numElems)
|
||||
|
||||
def MonsterCreateFlexVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(1, len(data), 1)
|
||||
for item in reversed(data):
|
||||
builder.PrependUint8(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateFlexVector(builder, data):
|
||||
MonsterCreateFlexVector(builder, data)
|
||||
|
||||
def MonsterAddTest5(builder, test5):
|
||||
builder.PrependUOffsetTRelativeSlot(31, flatbuffers.number_types.UOffsetTFlags.py_type(test5), 0)
|
||||
|
||||
@@ -1131,6 +1209,16 @@ def MonsterStartTest5Vector(builder, numElems):
|
||||
def StartTest5Vector(builder, numElems):
|
||||
return MonsterStartTest5Vector(builder, numElems)
|
||||
|
||||
def MonsterCreateTest5Vector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(4, len(data), 2)
|
||||
for item in reversed(data):
|
||||
item.Pack(builder)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateTest5Vector(builder, data):
|
||||
MonsterCreateTest5Vector(builder, data)
|
||||
|
||||
def MonsterAddVectorOfLongs(builder, vectorOfLongs):
|
||||
builder.PrependUOffsetTRelativeSlot(32, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfLongs), 0)
|
||||
|
||||
@@ -1143,6 +1231,16 @@ def MonsterStartVectorOfLongsVector(builder, numElems):
|
||||
def StartVectorOfLongsVector(builder, numElems):
|
||||
return MonsterStartVectorOfLongsVector(builder, numElems)
|
||||
|
||||
def MonsterCreateVectorOfLongsVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(8, len(data), 8)
|
||||
for item in reversed(data):
|
||||
builder.PrependInt64(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateVectorOfLongsVector(builder, data):
|
||||
MonsterCreateVectorOfLongsVector(builder, data)
|
||||
|
||||
def MonsterAddVectorOfDoubles(builder, vectorOfDoubles):
|
||||
builder.PrependUOffsetTRelativeSlot(33, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfDoubles), 0)
|
||||
|
||||
@@ -1155,6 +1253,16 @@ def MonsterStartVectorOfDoublesVector(builder, numElems):
|
||||
def StartVectorOfDoublesVector(builder, numElems):
|
||||
return MonsterStartVectorOfDoublesVector(builder, numElems)
|
||||
|
||||
def MonsterCreateVectorOfDoublesVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(8, len(data), 8)
|
||||
for item in reversed(data):
|
||||
builder.PrependFloat64(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateVectorOfDoublesVector(builder, data):
|
||||
MonsterCreateVectorOfDoublesVector(builder, data)
|
||||
|
||||
def MonsterAddParentNamespaceTest(builder, parentNamespaceTest):
|
||||
builder.PrependUOffsetTRelativeSlot(34, flatbuffers.number_types.UOffsetTFlags.py_type(parentNamespaceTest), 0)
|
||||
|
||||
@@ -1173,6 +1281,12 @@ def MonsterStartVectorOfReferrablesVector(builder, numElems):
|
||||
def StartVectorOfReferrablesVector(builder, numElems):
|
||||
return MonsterStartVectorOfReferrablesVector(builder, numElems)
|
||||
|
||||
def MonsterCreateVectorOfReferrablesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateVectorOfReferrablesVector(builder, data):
|
||||
MonsterCreateVectorOfReferrablesVector(builder, data)
|
||||
|
||||
def MonsterAddSingleWeakReference(builder, singleWeakReference):
|
||||
builder.PrependUint64Slot(36, singleWeakReference, 0)
|
||||
|
||||
@@ -1191,6 +1305,16 @@ def MonsterStartVectorOfWeakReferencesVector(builder, numElems):
|
||||
def StartVectorOfWeakReferencesVector(builder, numElems):
|
||||
return MonsterStartVectorOfWeakReferencesVector(builder, numElems)
|
||||
|
||||
def MonsterCreateVectorOfWeakReferencesVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(8, len(data), 8)
|
||||
for item in reversed(data):
|
||||
builder.PrependUint64(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateVectorOfWeakReferencesVector(builder, data):
|
||||
MonsterCreateVectorOfWeakReferencesVector(builder, data)
|
||||
|
||||
def MonsterAddVectorOfStrongReferrables(builder, vectorOfStrongReferrables):
|
||||
builder.PrependUOffsetTRelativeSlot(38, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfStrongReferrables), 0)
|
||||
|
||||
@@ -1203,6 +1327,12 @@ def MonsterStartVectorOfStrongReferrablesVector(builder, numElems):
|
||||
def StartVectorOfStrongReferrablesVector(builder, numElems):
|
||||
return MonsterStartVectorOfStrongReferrablesVector(builder, numElems)
|
||||
|
||||
def MonsterCreateVectorOfStrongReferrablesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateVectorOfStrongReferrablesVector(builder, data):
|
||||
MonsterCreateVectorOfStrongReferrablesVector(builder, data)
|
||||
|
||||
def MonsterAddCoOwningReference(builder, coOwningReference):
|
||||
builder.PrependUint64Slot(39, coOwningReference, 0)
|
||||
|
||||
@@ -1221,6 +1351,16 @@ def MonsterStartVectorOfCoOwningReferencesVector(builder, numElems):
|
||||
def StartVectorOfCoOwningReferencesVector(builder, numElems):
|
||||
return MonsterStartVectorOfCoOwningReferencesVector(builder, numElems)
|
||||
|
||||
def MonsterCreateVectorOfCoOwningReferencesVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(8, len(data), 8)
|
||||
for item in reversed(data):
|
||||
builder.PrependUint64(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateVectorOfCoOwningReferencesVector(builder, data):
|
||||
MonsterCreateVectorOfCoOwningReferencesVector(builder, data)
|
||||
|
||||
def MonsterAddNonOwningReference(builder, nonOwningReference):
|
||||
builder.PrependUint64Slot(41, nonOwningReference, 0)
|
||||
|
||||
@@ -1239,6 +1379,16 @@ def MonsterStartVectorOfNonOwningReferencesVector(builder, numElems):
|
||||
def StartVectorOfNonOwningReferencesVector(builder, numElems):
|
||||
return MonsterStartVectorOfNonOwningReferencesVector(builder, numElems)
|
||||
|
||||
def MonsterCreateVectorOfNonOwningReferencesVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(8, len(data), 8)
|
||||
for item in reversed(data):
|
||||
builder.PrependUint64(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateVectorOfNonOwningReferencesVector(builder, data):
|
||||
MonsterCreateVectorOfNonOwningReferencesVector(builder, data)
|
||||
|
||||
def MonsterAddAnyUniqueType(builder, anyUniqueType):
|
||||
builder.PrependUint8Slot(43, anyUniqueType, 0)
|
||||
|
||||
@@ -1275,6 +1425,16 @@ def MonsterStartVectorOfEnumsVector(builder, numElems):
|
||||
def StartVectorOfEnumsVector(builder, numElems):
|
||||
return MonsterStartVectorOfEnumsVector(builder, numElems)
|
||||
|
||||
def MonsterCreateVectorOfEnumsVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(1, len(data), 1)
|
||||
for item in reversed(data):
|
||||
builder.PrependUint8(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateVectorOfEnumsVector(builder, data):
|
||||
MonsterCreateVectorOfEnumsVector(builder, data)
|
||||
|
||||
def MonsterAddSignedEnum(builder, signedEnum):
|
||||
builder.PrependInt8Slot(48, signedEnum, -1)
|
||||
|
||||
@@ -1293,6 +1453,16 @@ def MonsterStartTestrequirednestedflatbufferVector(builder, numElems):
|
||||
def StartTestrequirednestedflatbufferVector(builder, numElems):
|
||||
return MonsterStartTestrequirednestedflatbufferVector(builder, numElems)
|
||||
|
||||
def MonsterCreateTestrequirednestedflatbufferVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(1, len(data), 1)
|
||||
for item in reversed(data):
|
||||
builder.PrependUint8(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateTestrequirednestedflatbufferVector(builder, data):
|
||||
MonsterCreateTestrequirednestedflatbufferVector(builder, data)
|
||||
|
||||
def MonsterMakeTestrequirednestedflatbufferVectorFromBytes(builder, bytes):
|
||||
builder.StartVector(1, len(bytes), 1)
|
||||
builder.head = builder.head - len(bytes)
|
||||
@@ -1312,6 +1482,12 @@ def MonsterStartScalarKeySortedTablesVector(builder, numElems):
|
||||
def StartScalarKeySortedTablesVector(builder, numElems):
|
||||
return MonsterStartScalarKeySortedTablesVector(builder, numElems)
|
||||
|
||||
def MonsterCreateScalarKeySortedTablesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def CreateScalarKeySortedTablesVector(builder, data):
|
||||
MonsterCreateScalarKeySortedTablesVector(builder, data)
|
||||
|
||||
def MonsterAddNativeInline(builder, nativeInline):
|
||||
builder.PrependStructSlot(51, flatbuffers.number_types.UOffsetTFlags.py_type(nativeInline), 0)
|
||||
|
||||
|
||||
@@ -17,12 +17,30 @@ public struct NestedStruct : IFlatbufferObject
|
||||
public NestedStruct __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public int A(int j) { return __p.bb.GetInt(__p.bb_pos + 0 + j * 4); }
|
||||
public const int ALength = 2;
|
||||
#if ENABLE_SPAN_T
|
||||
public Span<int> GetABytes() { return System.Runtime.InteropServices.MemoryMarshal.Cast<byte, int>(__p.bb.ToSpan(__p.bb_pos + 0, 8)); }
|
||||
#else
|
||||
public ArraySegment<byte>? GetABytes() { return __p.bb.ToArraySegment(__p.bb_pos + 0, 8);}
|
||||
#endif
|
||||
public void MutateA(int j, int a) { __p.bb.PutInt(__p.bb_pos + 0 + j * 4, a); }
|
||||
public MyGame.Example.TestEnum B { get { return (MyGame.Example.TestEnum)__p.bb.GetSbyte(__p.bb_pos + 8); } }
|
||||
public void MutateB(MyGame.Example.TestEnum b) { __p.bb.PutSbyte(__p.bb_pos + 8, (sbyte)b); }
|
||||
public MyGame.Example.TestEnum C(int j) { return (MyGame.Example.TestEnum)__p.bb.GetSbyte(__p.bb_pos + 9 + j * 1); }
|
||||
public const int CLength = 2;
|
||||
#if ENABLE_SPAN_T
|
||||
public Span<MyGame.Example.TestEnum> GetCBytes() { return System.Runtime.InteropServices.MemoryMarshal.Cast<byte, MyGame.Example.TestEnum>(__p.bb.ToSpan(__p.bb_pos + 9, 2)); }
|
||||
#else
|
||||
public ArraySegment<byte>? GetCBytes() { return __p.bb.ToArraySegment(__p.bb_pos + 9, 2);}
|
||||
#endif
|
||||
public void MutateC(int j, MyGame.Example.TestEnum c) { __p.bb.PutSbyte(__p.bb_pos + 9 + j * 1, (sbyte)c); }
|
||||
public long D(int j) { return __p.bb.GetLong(__p.bb_pos + 16 + j * 8); }
|
||||
public const int DLength = 2;
|
||||
#if ENABLE_SPAN_T
|
||||
public Span<long> GetDBytes() { return System.Runtime.InteropServices.MemoryMarshal.Cast<byte, long>(__p.bb.ToSpan(__p.bb_pos + 16, 16)); }
|
||||
#else
|
||||
public ArraySegment<byte>? GetDBytes() { return __p.bb.ToArraySegment(__p.bb_pos + 16, 16);}
|
||||
#endif
|
||||
public void MutateD(int j, long d) { __p.bb.PutLong(__p.bb_pos + 16 + j * 8, d); }
|
||||
|
||||
public static Offset<MyGame.Example.NestedStruct> CreateNestedStruct(FlatBufferBuilder builder, int[] A, MyGame.Example.TestEnum B, MyGame.Example.TestEnum[] C, long[] D) {
|
||||
|
||||
@@ -230,6 +230,16 @@ def TypeAliasesStartV8Vector(builder, numElems):
|
||||
def StartV8Vector(builder, numElems):
|
||||
return TypeAliasesStartV8Vector(builder, numElems)
|
||||
|
||||
def TypeAliasesCreateV8Vector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(1, len(data), 1)
|
||||
for item in reversed(data):
|
||||
builder.PrependInt8(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateV8Vector(builder, data):
|
||||
TypeAliasesCreateV8Vector(builder, data)
|
||||
|
||||
def TypeAliasesAddVf64(builder, vf64):
|
||||
builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(vf64), 0)
|
||||
|
||||
@@ -242,6 +252,16 @@ def TypeAliasesStartVf64Vector(builder, numElems):
|
||||
def StartVf64Vector(builder, numElems):
|
||||
return TypeAliasesStartVf64Vector(builder, numElems)
|
||||
|
||||
def TypeAliasesCreateVf64Vector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(8, len(data), 8)
|
||||
for item in reversed(data):
|
||||
builder.PrependFloat64(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateVf64Vector(builder, data):
|
||||
TypeAliasesCreateVf64Vector(builder, data)
|
||||
|
||||
def TypeAliasesEnd(builder):
|
||||
return builder.EndObject()
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import flatbuffers
|
||||
from flatbuffers.compat import import_numpy
|
||||
from typing import Any
|
||||
from typing import Iterable
|
||||
np = import_numpy()
|
||||
|
||||
class MonsterExtra(object):
|
||||
@@ -205,6 +206,16 @@ def MonsterExtraStartDvecVector(builder, numElems: int) -> int:
|
||||
def StartDvecVector(builder, numElems: int) -> int:
|
||||
return MonsterExtraStartDvecVector(builder, numElems)
|
||||
|
||||
def MonsterExtraCreateDvecVector(builder: flatbuffers.Builder, data: Iterable[Any]) -> int:
|
||||
data = list(data)
|
||||
builder.StartVector(8, len(data), 8)
|
||||
for item in reversed(data):
|
||||
builder.PrependFloat64(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateDvecVector(builder: flatbuffers.Builder, data: Iterable[Any]) -> int:
|
||||
MonsterExtraCreateDvecVector(builder, data)
|
||||
|
||||
def MonsterExtraAddFvec(builder: flatbuffers.Builder, fvec: int):
|
||||
builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(fvec), 0)
|
||||
|
||||
@@ -217,6 +228,16 @@ def MonsterExtraStartFvecVector(builder, numElems: int) -> int:
|
||||
def StartFvecVector(builder, numElems: int) -> int:
|
||||
return MonsterExtraStartFvecVector(builder, numElems)
|
||||
|
||||
def MonsterExtraCreateFvecVector(builder: flatbuffers.Builder, data: Iterable[Any]) -> int:
|
||||
data = list(data)
|
||||
builder.StartVector(4, len(data), 4)
|
||||
for item in reversed(data):
|
||||
builder.PrependFloat32(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def CreateFvecVector(builder: flatbuffers.Builder, data: Iterable[Any]) -> int:
|
||||
MonsterExtraCreateFvecVector(builder, data)
|
||||
|
||||
def MonsterExtraEnd(builder: flatbuffers.Builder) -> int:
|
||||
return builder.EndObject()
|
||||
|
||||
|
||||
@@ -77,9 +77,13 @@ def MonsterExtraAddF3(builder: flatbuffers.Builder, f3: float) -> None: ...
|
||||
def MonsterExtraAddDvec(builder: flatbuffers.Builder, dvec: uoffset) -> None: ...
|
||||
def MonsterExtraStartDvecVector(builder: flatbuffers.Builder, num_elems: int) -> uoffset: ...
|
||||
def StartDvecVector(builder: flatbuffers.Builder, num_elems: int) -> uoffset: ...
|
||||
def MonsterExtraCreateDvecVector(builder: flatbuffers.Builder, data: typing.Iterable[typing.Any]) -> uoffset: ...
|
||||
def CreateDvecVector(builder: flatbuffers.Builder, data: typing.Iterable[typing.Any]) -> uoffset: ...
|
||||
def MonsterExtraAddFvec(builder: flatbuffers.Builder, fvec: uoffset) -> None: ...
|
||||
def MonsterExtraStartFvecVector(builder: flatbuffers.Builder, num_elems: int) -> uoffset: ...
|
||||
def StartFvecVector(builder: flatbuffers.Builder, num_elems: int) -> uoffset: ...
|
||||
def MonsterExtraCreateFvecVector(builder: flatbuffers.Builder, data: typing.Iterable[typing.Any]) -> uoffset: ...
|
||||
def CreateFvecVector(builder: flatbuffers.Builder, data: typing.Iterable[typing.Any]) -> uoffset: ...
|
||||
def MonsterExtraEnd(builder: flatbuffers.Builder) -> uoffset: ...
|
||||
def End(builder: flatbuffers.Builder) -> uoffset: ...
|
||||
|
||||
|
||||
16
tests/cpp_vec_type_native_type_test.fbs
Normal file
16
tests/cpp_vec_type_native_type_test.fbs
Normal file
@@ -0,0 +1,16 @@
|
||||
native_include "cpp_vec_type_native_type_test_impl.h";
|
||||
|
||||
namespace CppVecNativeTypeTest;
|
||||
|
||||
struct Vec3 (native_type: "CppVecNativeTypeTest::Native::Vec3") {
|
||||
x: float;
|
||||
y: float;
|
||||
z: float;
|
||||
}
|
||||
|
||||
table Container {
|
||||
points: [Vec3] (cpp_vec_type: "CppVecNativeTypeTest::CustomVec");
|
||||
bytes: [ubyte] (cpp_vec_type: "CppVecNativeTypeTest::CustomVec");
|
||||
}
|
||||
|
||||
root_type Container;
|
||||
15
tests/cpp_vec_type_native_type_test_impl.cpp
Normal file
15
tests/cpp_vec_type_native_type_test_impl.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "cpp_vec_type_native_type_test_impl.h"
|
||||
|
||||
#include "cpp_vec_type_native_type_test_generated.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
CppVecNativeTypeTest::Vec3 Pack(
|
||||
const CppVecNativeTypeTest::Native::Vec3& obj) {
|
||||
return CppVecNativeTypeTest::Vec3(obj.x, obj.y, obj.z);
|
||||
}
|
||||
|
||||
const CppVecNativeTypeTest::Native::Vec3 UnPack(
|
||||
const CppVecNativeTypeTest::Vec3& obj) {
|
||||
return CppVecNativeTypeTest::Native::Vec3(obj.x(), obj.y(), obj.z());
|
||||
}
|
||||
} // namespace flatbuffers
|
||||
34
tests/cpp_vec_type_native_type_test_impl.h
Normal file
34
tests/cpp_vec_type_native_type_test_impl.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef CPP_VEC_TYPE_NATIVE_TYPE_TEST_IMPL_H
|
||||
#define CPP_VEC_TYPE_NATIVE_TYPE_TEST_IMPL_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace CppVecNativeTypeTest {
|
||||
|
||||
namespace Native {
|
||||
struct Vec3 {
|
||||
float x, y, z;
|
||||
Vec3() : x(0), y(0), z(0) {}
|
||||
Vec3(float x_, float y_, float z_) : x(x_), y(y_), z(z_) {}
|
||||
bool operator==(const Vec3& o) const {
|
||||
return x == o.x && y == o.y && z == o.z;
|
||||
}
|
||||
};
|
||||
} // namespace Native
|
||||
|
||||
template <typename T>
|
||||
struct CustomVec : public std::vector<T> {
|
||||
using std::vector<T>::vector;
|
||||
};
|
||||
|
||||
struct Vec3; // flatbuffers-generated struct
|
||||
|
||||
} // namespace CppVecNativeTypeTest
|
||||
|
||||
namespace flatbuffers {
|
||||
CppVecNativeTypeTest::Vec3 Pack(const CppVecNativeTypeTest::Native::Vec3& obj);
|
||||
const CppVecNativeTypeTest::Native::Vec3 UnPack(
|
||||
const CppVecNativeTypeTest::Vec3& obj);
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // CPP_VEC_TYPE_NATIVE_TYPE_TEST_IMPL_H
|
||||
17
tests/cpp_vec_type_test.fbs
Normal file
17
tests/cpp_vec_type_test.fbs
Normal file
@@ -0,0 +1,17 @@
|
||||
native_include "cpp_vec_type_test_impl.h";
|
||||
|
||||
namespace CppVecTest;
|
||||
|
||||
table Item {
|
||||
id: int;
|
||||
value: float;
|
||||
}
|
||||
|
||||
table Data {
|
||||
values: [int] (cpp_vec_type: "CppVecTest::CustomVec");
|
||||
items: [Item] (cpp_vec_type: "CppVecTest::CustomVec");
|
||||
strs: [string] (cpp_vec_type: "CppVecTest::CustomVec");
|
||||
regular: [int];
|
||||
}
|
||||
|
||||
root_type Data;
|
||||
15
tests/cpp_vec_type_test_impl.h
Normal file
15
tests/cpp_vec_type_test_impl.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef CPP_VEC_TYPE_TEST_IMPL_H
|
||||
#define CPP_VEC_TYPE_TEST_IMPL_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace CppVecTest {
|
||||
|
||||
template<typename T>
|
||||
struct CustomVec : public std::vector<T> {
|
||||
using std::vector<T>::vector;
|
||||
};
|
||||
|
||||
} // namespace CppVecTest
|
||||
|
||||
#endif // CPP_VEC_TYPE_TEST_IMPL_H
|
||||
@@ -71,3 +71,12 @@ class SchemaTests:
|
||||
schema_json["enums"][0]["values"][2]["attributes"][1]["value"]
|
||||
== "Value 3 (deprecated)"
|
||||
)
|
||||
|
||||
def CircularStructDependency(self):
|
||||
try:
|
||||
flatc(["-c", "circular_struct_dependency.fbs"])
|
||||
assert False, "Expected flatc to fail on circular struct dependency"
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
flatc(["-c", "circular_table.fbs"])
|
||||
479
tests/include_test1_generated.rs
Normal file
479
tests/include_test1_generated.rs
Normal file
@@ -0,0 +1,479 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// @generated
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
pub enum TableAOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct TableA<'a> {
|
||||
pub _tab: ::flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> ::flatbuffers::Follow<'a> for TableA<'a> {
|
||||
type Inner = TableA<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TableA<'a> {
|
||||
pub const VT_B: ::flatbuffers::VOffsetT = 4;
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"TableA"
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self {
|
||||
TableA { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>(
|
||||
_fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>,
|
||||
args: &'args TableAArgs<'args>
|
||||
) -> ::flatbuffers::WIPOffset<TableA<'bldr>> {
|
||||
let mut builder = TableABuilder::new(_fbb);
|
||||
if let Some(x) = args.b { builder.add_b(x); }
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> TableAT {
|
||||
let b = self.b().map(|x| {
|
||||
alloc::boxed::Box::new(x.unpack())
|
||||
});
|
||||
TableAT {
|
||||
b,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn b(&self) -> Option<my_game::other_name_space::TableB<'a>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)}
|
||||
}
|
||||
}
|
||||
|
||||
impl ::flatbuffers::Verifiable for TableA<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut ::flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), ::flatbuffers::InvalidFlatbuffer> {
|
||||
v.visit_table(pos)?
|
||||
.visit_field::<::flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>("b", Self::VT_B, false)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct TableAArgs<'a> {
|
||||
pub b: Option<::flatbuffers::WIPOffset<my_game::other_name_space::TableB<'a>>>,
|
||||
}
|
||||
impl<'a> Default for TableAArgs<'a> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
TableAArgs {
|
||||
b: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TableABuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> {
|
||||
fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>,
|
||||
start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableABuilder<'a, 'b, A> {
|
||||
#[inline]
|
||||
pub fn add_b(&mut self, b: ::flatbuffers::WIPOffset<my_game::other_name_space::TableB<'b >>) {
|
||||
self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<my_game::other_name_space::TableB>>(TableA::VT_B, b);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableABuilder<'a, 'b, A> {
|
||||
let start = _fbb.start_table();
|
||||
TableABuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> ::flatbuffers::WIPOffset<TableA<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
::flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl ::core::fmt::Debug for TableA<'_> {
|
||||
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
|
||||
let mut ds = f.debug_struct("TableA");
|
||||
ds.field("b", &self.b());
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct TableAT {
|
||||
pub b: Option<alloc::boxed::Box<my_game::other_name_space::TableBT>>,
|
||||
}
|
||||
impl Default for TableAT {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
b: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl TableAT {
|
||||
pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(
|
||||
&self,
|
||||
_fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A>
|
||||
) -> ::flatbuffers::WIPOffset<TableA<'b>> {
|
||||
let b = self.b.as_ref().map(|x|{
|
||||
x.pack(_fbb)
|
||||
});
|
||||
TableA::create(_fbb, &TableAArgs{
|
||||
b,
|
||||
})
|
||||
}
|
||||
}
|
||||
#[allow(unused_imports, dead_code)]
|
||||
pub mod my_game {
|
||||
|
||||
extern crate alloc;
|
||||
#[allow(unused_imports, dead_code)]
|
||||
pub mod other_name_space {
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
pub const ENUM_MIN_FROM_INCLUDE: i64 = 0;
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
pub const ENUM_MAX_FROM_INCLUDE: i64 = 0;
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub const ENUM_VALUES_FROM_INCLUDE: [FromInclude; 1] = [
|
||||
FromInclude::IncludeVal,
|
||||
];
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||
#[repr(transparent)]
|
||||
pub struct FromInclude(pub i64);
|
||||
#[allow(non_upper_case_globals)]
|
||||
impl FromInclude {
|
||||
pub const IncludeVal: Self = Self(0);
|
||||
|
||||
pub const ENUM_MIN: i64 = 0;
|
||||
pub const ENUM_MAX: i64 = 0;
|
||||
pub const ENUM_VALUES: &'static [Self] = &[
|
||||
Self::IncludeVal,
|
||||
];
|
||||
/// Returns the variant's name or "" if unknown.
|
||||
pub fn variant_name(self) -> Option<&'static str> {
|
||||
match self {
|
||||
Self::IncludeVal => Some("IncludeVal"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl ::core::fmt::Debug for FromInclude {
|
||||
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
||||
if let Some(name) = self.variant_name() {
|
||||
f.write_str(name)
|
||||
} else {
|
||||
f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'a> ::flatbuffers::Follow<'a> for FromInclude {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe { ::flatbuffers::read_scalar_at::<i64>(buf, loc) };
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::flatbuffers::Push for FromInclude {
|
||||
type Output = FromInclude;
|
||||
#[inline]
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
unsafe { ::flatbuffers::emplace_scalar::<i64>(dst, self.0) };
|
||||
}
|
||||
}
|
||||
|
||||
impl ::flatbuffers::EndianScalar for FromInclude {
|
||||
type Scalar = i64;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> i64 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(v: i64) -> Self {
|
||||
let b = i64::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ::flatbuffers::Verifiable for FromInclude {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut ::flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), ::flatbuffers::InvalidFlatbuffer> {
|
||||
i64::run_verifier(v, pos)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::flatbuffers::SimpleToVerifyInSlice for FromInclude {}
|
||||
// struct Unused, aligned to 4
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub struct Unused(pub [u8; 4]);
|
||||
impl Default for Unused {
|
||||
fn default() -> Self {
|
||||
Self([0; 4])
|
||||
}
|
||||
}
|
||||
impl ::core::fmt::Debug for Unused {
|
||||
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
||||
f.debug_struct("Unused")
|
||||
.field("a", &self.a())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl ::flatbuffers::SimpleToVerifyInSlice for Unused {}
|
||||
impl<'a> ::flatbuffers::Follow<'a> for Unused {
|
||||
type Inner = &'a Unused;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe { <&'a Unused>::follow(buf, loc) }
|
||||
}
|
||||
}
|
||||
impl<'a> ::flatbuffers::Follow<'a> for &'a Unused {
|
||||
type Inner = &'a Unused;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe { ::flatbuffers::follow_cast_ref::<Unused>(buf, loc) }
|
||||
}
|
||||
}
|
||||
impl<'b> ::flatbuffers::Push for Unused {
|
||||
type Output = Unused;
|
||||
#[inline]
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = unsafe { ::core::slice::from_raw_parts(self as *const Unused as *const u8, <Self as ::flatbuffers::Push>::size()) };
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> ::flatbuffers::PushAlignment {
|
||||
::flatbuffers::PushAlignment::new(4)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ::flatbuffers::Verifiable for Unused {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut ::flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), ::flatbuffers::InvalidFlatbuffer> {
|
||||
v.in_buffer::<Self>(pos)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Unused {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
a: i32,
|
||||
) -> Self {
|
||||
let mut s = Self([0; 4]);
|
||||
s.set_a(a);
|
||||
s
|
||||
}
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"MyGame.OtherNameSpace.Unused"
|
||||
}
|
||||
|
||||
pub fn a(&self) -> i32 {
|
||||
let mut mem = ::core::mem::MaybeUninit::<<i32 as ::flatbuffers::EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
::flatbuffers::EndianScalar::from_little_endian(unsafe {
|
||||
::core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
::core::mem::size_of::<<i32 as ::flatbuffers::EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_a(&mut self, x: i32) {
|
||||
let x_le = ::flatbuffers::EndianScalar::to_little_endian(x);
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
::core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
::core::mem::size_of::<<i32 as ::flatbuffers::EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> UnusedT {
|
||||
UnusedT {
|
||||
a: self.a(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct UnusedT {
|
||||
pub a: i32,
|
||||
}
|
||||
impl UnusedT {
|
||||
pub fn pack(&self) -> Unused {
|
||||
Unused::new(
|
||||
self.a,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum TableBOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct TableB<'a> {
|
||||
pub _tab: ::flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> ::flatbuffers::Follow<'a> for TableB<'a> {
|
||||
type Inner = TableB<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TableB<'a> {
|
||||
pub const VT_A: ::flatbuffers::VOffsetT = 4;
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"MyGame.OtherNameSpace.TableB"
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self {
|
||||
TableB { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>(
|
||||
_fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>,
|
||||
args: &'args TableBArgs<'args>
|
||||
) -> ::flatbuffers::WIPOffset<TableB<'bldr>> {
|
||||
let mut builder = TableBBuilder::new(_fbb);
|
||||
if let Some(x) = args.a { builder.add_a(x); }
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> TableBT {
|
||||
let a = self.a().map(|x| {
|
||||
alloc::boxed::Box::new(x.unpack())
|
||||
});
|
||||
TableBT {
|
||||
a,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn a(&self) -> Option<super::super::TableA<'a>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)}
|
||||
}
|
||||
}
|
||||
|
||||
impl ::flatbuffers::Verifiable for TableB<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut ::flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), ::flatbuffers::InvalidFlatbuffer> {
|
||||
v.visit_table(pos)?
|
||||
.visit_field::<::flatbuffers::ForwardsUOffset<super::super::TableA>>("a", Self::VT_A, false)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct TableBArgs<'a> {
|
||||
pub a: Option<::flatbuffers::WIPOffset<super::super::TableA<'a>>>,
|
||||
}
|
||||
impl<'a> Default for TableBArgs<'a> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
TableBArgs {
|
||||
a: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TableBBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> {
|
||||
fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>,
|
||||
start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableBBuilder<'a, 'b, A> {
|
||||
#[inline]
|
||||
pub fn add_a(&mut self, a: ::flatbuffers::WIPOffset<super::super::TableA<'b >>) {
|
||||
self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<super::super::TableA>>(TableB::VT_A, a);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableBBuilder<'a, 'b, A> {
|
||||
let start = _fbb.start_table();
|
||||
TableBBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> ::flatbuffers::WIPOffset<TableB<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
::flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl ::core::fmt::Debug for TableB<'_> {
|
||||
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
|
||||
let mut ds = f.debug_struct("TableB");
|
||||
ds.field("a", &self.a());
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct TableBT {
|
||||
pub a: Option<alloc::boxed::Box<super::super::TableAT>>,
|
||||
}
|
||||
impl Default for TableBT {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
a: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl TableBT {
|
||||
pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(
|
||||
&self,
|
||||
_fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A>
|
||||
) -> ::flatbuffers::WIPOffset<TableB<'b>> {
|
||||
let a = self.a.as_ref().map(|x|{
|
||||
x.pack(_fbb)
|
||||
});
|
||||
TableB::create(_fbb, &TableBArgs{
|
||||
a,
|
||||
})
|
||||
}
|
||||
}
|
||||
} // pub mod OtherNameSpace
|
||||
} // pub mod MyGame
|
||||
|
||||
479
tests/include_test2_generated.rs
Normal file
479
tests/include_test2_generated.rs
Normal file
@@ -0,0 +1,479 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// @generated
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
pub enum TableAOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct TableA<'a> {
|
||||
pub _tab: ::flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> ::flatbuffers::Follow<'a> for TableA<'a> {
|
||||
type Inner = TableA<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TableA<'a> {
|
||||
pub const VT_B: ::flatbuffers::VOffsetT = 4;
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"TableA"
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self {
|
||||
TableA { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>(
|
||||
_fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>,
|
||||
args: &'args TableAArgs<'args>
|
||||
) -> ::flatbuffers::WIPOffset<TableA<'bldr>> {
|
||||
let mut builder = TableABuilder::new(_fbb);
|
||||
if let Some(x) = args.b { builder.add_b(x); }
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> TableAT {
|
||||
let b = self.b().map(|x| {
|
||||
alloc::boxed::Box::new(x.unpack())
|
||||
});
|
||||
TableAT {
|
||||
b,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn b(&self) -> Option<my_game::other_name_space::TableB<'a>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)}
|
||||
}
|
||||
}
|
||||
|
||||
impl ::flatbuffers::Verifiable for TableA<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut ::flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), ::flatbuffers::InvalidFlatbuffer> {
|
||||
v.visit_table(pos)?
|
||||
.visit_field::<::flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>("b", Self::VT_B, false)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct TableAArgs<'a> {
|
||||
pub b: Option<::flatbuffers::WIPOffset<my_game::other_name_space::TableB<'a>>>,
|
||||
}
|
||||
impl<'a> Default for TableAArgs<'a> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
TableAArgs {
|
||||
b: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TableABuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> {
|
||||
fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>,
|
||||
start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableABuilder<'a, 'b, A> {
|
||||
#[inline]
|
||||
pub fn add_b(&mut self, b: ::flatbuffers::WIPOffset<my_game::other_name_space::TableB<'b >>) {
|
||||
self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<my_game::other_name_space::TableB>>(TableA::VT_B, b);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableABuilder<'a, 'b, A> {
|
||||
let start = _fbb.start_table();
|
||||
TableABuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> ::flatbuffers::WIPOffset<TableA<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
::flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl ::core::fmt::Debug for TableA<'_> {
|
||||
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
|
||||
let mut ds = f.debug_struct("TableA");
|
||||
ds.field("b", &self.b());
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct TableAT {
|
||||
pub b: Option<alloc::boxed::Box<my_game::other_name_space::TableBT>>,
|
||||
}
|
||||
impl Default for TableAT {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
b: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl TableAT {
|
||||
pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(
|
||||
&self,
|
||||
_fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A>
|
||||
) -> ::flatbuffers::WIPOffset<TableA<'b>> {
|
||||
let b = self.b.as_ref().map(|x|{
|
||||
x.pack(_fbb)
|
||||
});
|
||||
TableA::create(_fbb, &TableAArgs{
|
||||
b,
|
||||
})
|
||||
}
|
||||
}
|
||||
#[allow(unused_imports, dead_code)]
|
||||
pub mod my_game {
|
||||
|
||||
extern crate alloc;
|
||||
#[allow(unused_imports, dead_code)]
|
||||
pub mod other_name_space {
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
pub const ENUM_MIN_FROM_INCLUDE: i64 = 0;
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
pub const ENUM_MAX_FROM_INCLUDE: i64 = 0;
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub const ENUM_VALUES_FROM_INCLUDE: [FromInclude; 1] = [
|
||||
FromInclude::IncludeVal,
|
||||
];
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||
#[repr(transparent)]
|
||||
pub struct FromInclude(pub i64);
|
||||
#[allow(non_upper_case_globals)]
|
||||
impl FromInclude {
|
||||
pub const IncludeVal: Self = Self(0);
|
||||
|
||||
pub const ENUM_MIN: i64 = 0;
|
||||
pub const ENUM_MAX: i64 = 0;
|
||||
pub const ENUM_VALUES: &'static [Self] = &[
|
||||
Self::IncludeVal,
|
||||
];
|
||||
/// Returns the variant's name or "" if unknown.
|
||||
pub fn variant_name(self) -> Option<&'static str> {
|
||||
match self {
|
||||
Self::IncludeVal => Some("IncludeVal"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl ::core::fmt::Debug for FromInclude {
|
||||
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
||||
if let Some(name) = self.variant_name() {
|
||||
f.write_str(name)
|
||||
} else {
|
||||
f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'a> ::flatbuffers::Follow<'a> for FromInclude {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe { ::flatbuffers::read_scalar_at::<i64>(buf, loc) };
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::flatbuffers::Push for FromInclude {
|
||||
type Output = FromInclude;
|
||||
#[inline]
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
unsafe { ::flatbuffers::emplace_scalar::<i64>(dst, self.0) };
|
||||
}
|
||||
}
|
||||
|
||||
impl ::flatbuffers::EndianScalar for FromInclude {
|
||||
type Scalar = i64;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> i64 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(v: i64) -> Self {
|
||||
let b = i64::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ::flatbuffers::Verifiable for FromInclude {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut ::flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), ::flatbuffers::InvalidFlatbuffer> {
|
||||
i64::run_verifier(v, pos)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::flatbuffers::SimpleToVerifyInSlice for FromInclude {}
|
||||
// struct Unused, aligned to 4
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub struct Unused(pub [u8; 4]);
|
||||
impl Default for Unused {
|
||||
fn default() -> Self {
|
||||
Self([0; 4])
|
||||
}
|
||||
}
|
||||
impl ::core::fmt::Debug for Unused {
|
||||
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
||||
f.debug_struct("Unused")
|
||||
.field("a", &self.a())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl ::flatbuffers::SimpleToVerifyInSlice for Unused {}
|
||||
impl<'a> ::flatbuffers::Follow<'a> for Unused {
|
||||
type Inner = &'a Unused;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe { <&'a Unused>::follow(buf, loc) }
|
||||
}
|
||||
}
|
||||
impl<'a> ::flatbuffers::Follow<'a> for &'a Unused {
|
||||
type Inner = &'a Unused;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe { ::flatbuffers::follow_cast_ref::<Unused>(buf, loc) }
|
||||
}
|
||||
}
|
||||
impl<'b> ::flatbuffers::Push for Unused {
|
||||
type Output = Unused;
|
||||
#[inline]
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = unsafe { ::core::slice::from_raw_parts(self as *const Unused as *const u8, <Self as ::flatbuffers::Push>::size()) };
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> ::flatbuffers::PushAlignment {
|
||||
::flatbuffers::PushAlignment::new(4)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ::flatbuffers::Verifiable for Unused {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut ::flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), ::flatbuffers::InvalidFlatbuffer> {
|
||||
v.in_buffer::<Self>(pos)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Unused {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
a: i32,
|
||||
) -> Self {
|
||||
let mut s = Self([0; 4]);
|
||||
s.set_a(a);
|
||||
s
|
||||
}
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"MyGame.OtherNameSpace.Unused"
|
||||
}
|
||||
|
||||
pub fn a(&self) -> i32 {
|
||||
let mut mem = ::core::mem::MaybeUninit::<<i32 as ::flatbuffers::EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
::flatbuffers::EndianScalar::from_little_endian(unsafe {
|
||||
::core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
::core::mem::size_of::<<i32 as ::flatbuffers::EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_a(&mut self, x: i32) {
|
||||
let x_le = ::flatbuffers::EndianScalar::to_little_endian(x);
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
::core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
::core::mem::size_of::<<i32 as ::flatbuffers::EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> UnusedT {
|
||||
UnusedT {
|
||||
a: self.a(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct UnusedT {
|
||||
pub a: i32,
|
||||
}
|
||||
impl UnusedT {
|
||||
pub fn pack(&self) -> Unused {
|
||||
Unused::new(
|
||||
self.a,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum TableBOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct TableB<'a> {
|
||||
pub _tab: ::flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> ::flatbuffers::Follow<'a> for TableB<'a> {
|
||||
type Inner = TableB<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TableB<'a> {
|
||||
pub const VT_A: ::flatbuffers::VOffsetT = 4;
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"MyGame.OtherNameSpace.TableB"
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self {
|
||||
TableB { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>(
|
||||
_fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>,
|
||||
args: &'args TableBArgs<'args>
|
||||
) -> ::flatbuffers::WIPOffset<TableB<'bldr>> {
|
||||
let mut builder = TableBBuilder::new(_fbb);
|
||||
if let Some(x) = args.a { builder.add_a(x); }
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> TableBT {
|
||||
let a = self.a().map(|x| {
|
||||
alloc::boxed::Box::new(x.unpack())
|
||||
});
|
||||
TableBT {
|
||||
a,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn a(&self) -> Option<super::super::TableA<'a>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)}
|
||||
}
|
||||
}
|
||||
|
||||
impl ::flatbuffers::Verifiable for TableB<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut ::flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), ::flatbuffers::InvalidFlatbuffer> {
|
||||
v.visit_table(pos)?
|
||||
.visit_field::<::flatbuffers::ForwardsUOffset<super::super::TableA>>("a", Self::VT_A, false)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct TableBArgs<'a> {
|
||||
pub a: Option<::flatbuffers::WIPOffset<super::super::TableA<'a>>>,
|
||||
}
|
||||
impl<'a> Default for TableBArgs<'a> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
TableBArgs {
|
||||
a: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TableBBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> {
|
||||
fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>,
|
||||
start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableBBuilder<'a, 'b, A> {
|
||||
#[inline]
|
||||
pub fn add_a(&mut self, a: ::flatbuffers::WIPOffset<super::super::TableA<'b >>) {
|
||||
self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<super::super::TableA>>(TableB::VT_A, a);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableBBuilder<'a, 'b, A> {
|
||||
let start = _fbb.start_table();
|
||||
TableBBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> ::flatbuffers::WIPOffset<TableB<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
::flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl ::core::fmt::Debug for TableB<'_> {
|
||||
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
|
||||
let mut ds = f.debug_struct("TableB");
|
||||
ds.field("a", &self.a());
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct TableBT {
|
||||
pub a: Option<alloc::boxed::Box<super::super::TableAT>>,
|
||||
}
|
||||
impl Default for TableBT {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
a: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl TableBT {
|
||||
pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(
|
||||
&self,
|
||||
_fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A>
|
||||
) -> ::flatbuffers::WIPOffset<TableB<'b>> {
|
||||
let a = self.a.as_ref().map(|x|{
|
||||
x.pack(_fbb)
|
||||
});
|
||||
TableB::create(_fbb, &TableBArgs{
|
||||
a,
|
||||
})
|
||||
}
|
||||
}
|
||||
} // pub mod OtherNameSpace
|
||||
} // pub mod MyGame
|
||||
|
||||
@@ -1761,6 +1761,13 @@ def MonsterAddInventory(builder, inventory):
|
||||
def MonsterStartInventoryVector(builder, numElems):
|
||||
return builder.StartVector(1, numElems, 1)
|
||||
|
||||
def MonsterCreateInventoryVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(1, len(data), 1)
|
||||
for item in reversed(data):
|
||||
builder.PrependUint8(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def MonsterAddColor(builder, color):
|
||||
builder.PrependUint8Slot(6, color, 8)
|
||||
|
||||
@@ -1776,18 +1783,31 @@ def MonsterAddTest4(builder, test4):
|
||||
def MonsterStartTest4Vector(builder, numElems):
|
||||
return builder.StartVector(4, numElems, 2)
|
||||
|
||||
def MonsterCreateTest4Vector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(4, len(data), 2)
|
||||
for item in reversed(data):
|
||||
item.Pack(builder)
|
||||
return builder.EndVector()
|
||||
|
||||
def MonsterAddTestarrayofstring(builder, testarrayofstring):
|
||||
builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring), 0)
|
||||
|
||||
def MonsterStartTestarrayofstringVector(builder, numElems):
|
||||
return builder.StartVector(4, numElems, 4)
|
||||
|
||||
def MonsterCreateTestarrayofstringVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def MonsterAddTestarrayoftables(builder, testarrayoftables):
|
||||
builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayoftables), 0)
|
||||
|
||||
def MonsterStartTestarrayoftablesVector(builder, numElems):
|
||||
return builder.StartVector(4, numElems, 4)
|
||||
|
||||
def MonsterCreateTestarrayoftablesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def MonsterAddEnemy(builder, enemy):
|
||||
builder.PrependUOffsetTRelativeSlot(12, flatbuffers.number_types.UOffsetTFlags.py_type(enemy), 0)
|
||||
|
||||
@@ -1797,6 +1817,13 @@ def MonsterAddTestnestedflatbuffer(builder, testnestedflatbuffer):
|
||||
def MonsterStartTestnestedflatbufferVector(builder, numElems):
|
||||
return builder.StartVector(1, numElems, 1)
|
||||
|
||||
def MonsterCreateTestnestedflatbufferVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(1, len(data), 1)
|
||||
for item in reversed(data):
|
||||
builder.PrependUint8(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def MonsterMakeTestnestedflatbufferVectorFromBytes(builder, bytes):
|
||||
builder.StartVector(1, len(bytes), 1)
|
||||
builder.head = builder.head - len(bytes)
|
||||
@@ -1838,6 +1865,13 @@ def MonsterAddTestarrayofbools(builder, testarrayofbools):
|
||||
def MonsterStartTestarrayofboolsVector(builder, numElems):
|
||||
return builder.StartVector(1, numElems, 1)
|
||||
|
||||
def MonsterCreateTestarrayofboolsVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(1, len(data), 1)
|
||||
for item in reversed(data):
|
||||
builder.PrependBool(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def MonsterAddTestf(builder, testf):
|
||||
builder.PrependFloat32Slot(25, testf, 3.14159)
|
||||
|
||||
@@ -1853,36 +1887,74 @@ def MonsterAddTestarrayofstring2(builder, testarrayofstring2):
|
||||
def MonsterStartTestarrayofstring2Vector(builder, numElems):
|
||||
return builder.StartVector(4, numElems, 4)
|
||||
|
||||
def MonsterCreateTestarrayofstring2Vector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def MonsterAddTestarrayofsortedstruct(builder, testarrayofsortedstruct):
|
||||
builder.PrependUOffsetTRelativeSlot(29, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofsortedstruct), 0)
|
||||
|
||||
def MonsterStartTestarrayofsortedstructVector(builder, numElems):
|
||||
return builder.StartVector(8, numElems, 4)
|
||||
|
||||
def MonsterCreateTestarrayofsortedstructVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(8, len(data), 4)
|
||||
for item in reversed(data):
|
||||
item.Pack(builder)
|
||||
return builder.EndVector()
|
||||
|
||||
def MonsterAddFlex(builder, flex):
|
||||
builder.PrependUOffsetTRelativeSlot(30, flatbuffers.number_types.UOffsetTFlags.py_type(flex), 0)
|
||||
|
||||
def MonsterStartFlexVector(builder, numElems):
|
||||
return builder.StartVector(1, numElems, 1)
|
||||
|
||||
def MonsterCreateFlexVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(1, len(data), 1)
|
||||
for item in reversed(data):
|
||||
builder.PrependUint8(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def MonsterAddTest5(builder, test5):
|
||||
builder.PrependUOffsetTRelativeSlot(31, flatbuffers.number_types.UOffsetTFlags.py_type(test5), 0)
|
||||
|
||||
def MonsterStartTest5Vector(builder, numElems):
|
||||
return builder.StartVector(4, numElems, 2)
|
||||
|
||||
def MonsterCreateTest5Vector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(4, len(data), 2)
|
||||
for item in reversed(data):
|
||||
item.Pack(builder)
|
||||
return builder.EndVector()
|
||||
|
||||
def MonsterAddVectorOfLongs(builder, vectorOfLongs):
|
||||
builder.PrependUOffsetTRelativeSlot(32, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfLongs), 0)
|
||||
|
||||
def MonsterStartVectorOfLongsVector(builder, numElems):
|
||||
return builder.StartVector(8, numElems, 8)
|
||||
|
||||
def MonsterCreateVectorOfLongsVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(8, len(data), 8)
|
||||
for item in reversed(data):
|
||||
builder.PrependInt64(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def MonsterAddVectorOfDoubles(builder, vectorOfDoubles):
|
||||
builder.PrependUOffsetTRelativeSlot(33, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfDoubles), 0)
|
||||
|
||||
def MonsterStartVectorOfDoublesVector(builder, numElems):
|
||||
return builder.StartVector(8, numElems, 8)
|
||||
|
||||
def MonsterCreateVectorOfDoublesVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(8, len(data), 8)
|
||||
for item in reversed(data):
|
||||
builder.PrependFloat64(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def MonsterAddParentNamespaceTest(builder, parentNamespaceTest):
|
||||
builder.PrependUOffsetTRelativeSlot(34, flatbuffers.number_types.UOffsetTFlags.py_type(parentNamespaceTest), 0)
|
||||
|
||||
@@ -1892,6 +1964,9 @@ def MonsterAddVectorOfReferrables(builder, vectorOfReferrables):
|
||||
def MonsterStartVectorOfReferrablesVector(builder, numElems):
|
||||
return builder.StartVector(4, numElems, 4)
|
||||
|
||||
def MonsterCreateVectorOfReferrablesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def MonsterAddSingleWeakReference(builder, singleWeakReference):
|
||||
builder.PrependUint64Slot(36, singleWeakReference, 0)
|
||||
|
||||
@@ -1901,12 +1976,22 @@ def MonsterAddVectorOfWeakReferences(builder, vectorOfWeakReferences):
|
||||
def MonsterStartVectorOfWeakReferencesVector(builder, numElems):
|
||||
return builder.StartVector(8, numElems, 8)
|
||||
|
||||
def MonsterCreateVectorOfWeakReferencesVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(8, len(data), 8)
|
||||
for item in reversed(data):
|
||||
builder.PrependUint64(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def MonsterAddVectorOfStrongReferrables(builder, vectorOfStrongReferrables):
|
||||
builder.PrependUOffsetTRelativeSlot(38, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfStrongReferrables), 0)
|
||||
|
||||
def MonsterStartVectorOfStrongReferrablesVector(builder, numElems):
|
||||
return builder.StartVector(4, numElems, 4)
|
||||
|
||||
def MonsterCreateVectorOfStrongReferrablesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def MonsterAddCoOwningReference(builder, coOwningReference):
|
||||
builder.PrependUint64Slot(39, coOwningReference, 0)
|
||||
|
||||
@@ -1916,6 +2001,13 @@ def MonsterAddVectorOfCoOwningReferences(builder, vectorOfCoOwningReferences):
|
||||
def MonsterStartVectorOfCoOwningReferencesVector(builder, numElems):
|
||||
return builder.StartVector(8, numElems, 8)
|
||||
|
||||
def MonsterCreateVectorOfCoOwningReferencesVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(8, len(data), 8)
|
||||
for item in reversed(data):
|
||||
builder.PrependUint64(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def MonsterAddNonOwningReference(builder, nonOwningReference):
|
||||
builder.PrependUint64Slot(41, nonOwningReference, 0)
|
||||
|
||||
@@ -1925,6 +2017,13 @@ def MonsterAddVectorOfNonOwningReferences(builder, vectorOfNonOwningReferences):
|
||||
def MonsterStartVectorOfNonOwningReferencesVector(builder, numElems):
|
||||
return builder.StartVector(8, numElems, 8)
|
||||
|
||||
def MonsterCreateVectorOfNonOwningReferencesVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(8, len(data), 8)
|
||||
for item in reversed(data):
|
||||
builder.PrependUint64(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def MonsterAddAnyUniqueType(builder, anyUniqueType):
|
||||
builder.PrependUint8Slot(43, anyUniqueType, 0)
|
||||
|
||||
@@ -1943,6 +2042,13 @@ def MonsterAddVectorOfEnums(builder, vectorOfEnums):
|
||||
def MonsterStartVectorOfEnumsVector(builder, numElems):
|
||||
return builder.StartVector(1, numElems, 1)
|
||||
|
||||
def MonsterCreateVectorOfEnumsVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(1, len(data), 1)
|
||||
for item in reversed(data):
|
||||
builder.PrependUint8(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def MonsterAddSignedEnum(builder, signedEnum):
|
||||
builder.PrependInt8Slot(48, signedEnum, -1)
|
||||
|
||||
@@ -1952,6 +2058,13 @@ def MonsterAddTestrequirednestedflatbuffer(builder, testrequirednestedflatbuffer
|
||||
def MonsterStartTestrequirednestedflatbufferVector(builder, numElems):
|
||||
return builder.StartVector(1, numElems, 1)
|
||||
|
||||
def MonsterCreateTestrequirednestedflatbufferVector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(1, len(data), 1)
|
||||
for item in reversed(data):
|
||||
builder.PrependUint8(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def MonsterMakeTestrequirednestedflatbufferVectorFromBytes(builder, bytes):
|
||||
builder.StartVector(1, len(bytes), 1)
|
||||
builder.head = builder.head - len(bytes)
|
||||
@@ -1963,6 +2076,9 @@ def MonsterAddScalarKeySortedTables(builder, scalarKeySortedTables):
|
||||
def MonsterStartScalarKeySortedTablesVector(builder, numElems):
|
||||
return builder.StartVector(4, numElems, 4)
|
||||
|
||||
def MonsterCreateScalarKeySortedTablesVector(builder, data):
|
||||
return builder.CreateVectorOfTables(data)
|
||||
|
||||
def MonsterAddNativeInline(builder, nativeInline):
|
||||
builder.PrependStructSlot(51, flatbuffers.number_types.UOffsetTFlags.py_type(nativeInline), 0)
|
||||
|
||||
@@ -2792,12 +2908,26 @@ def TypeAliasesAddV8(builder, v8):
|
||||
def TypeAliasesStartV8Vector(builder, numElems):
|
||||
return builder.StartVector(1, numElems, 1)
|
||||
|
||||
def TypeAliasesCreateV8Vector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(1, len(data), 1)
|
||||
for item in reversed(data):
|
||||
builder.PrependInt8(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def TypeAliasesAddVf64(builder, vf64):
|
||||
builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(vf64), 0)
|
||||
|
||||
def TypeAliasesStartVf64Vector(builder, numElems):
|
||||
return builder.StartVector(8, numElems, 8)
|
||||
|
||||
def TypeAliasesCreateVf64Vector(builder, data):
|
||||
data = list(data)
|
||||
builder.StartVector(8, len(data), 8)
|
||||
for item in reversed(data):
|
||||
builder.PrependFloat64(item)
|
||||
return builder.EndVector()
|
||||
|
||||
def TypeAliasesEnd(builder):
|
||||
return builder.EndObject()
|
||||
|
||||
|
||||
@@ -14,6 +14,12 @@ struct Vector3DAlt (native_type:"Native::Vector3D", native_type_pack_name:"Vecto
|
||||
c:float;
|
||||
}
|
||||
|
||||
struct Vector3DSimple {
|
||||
x:float;
|
||||
y:float;
|
||||
z:float;
|
||||
}
|
||||
|
||||
table Matrix (native_type:"Native::Matrix") {
|
||||
rows:int32;
|
||||
columns:int32;
|
||||
@@ -27,6 +33,8 @@ table ApplicationData {
|
||||
position_inline:Vector3D (native_inline);
|
||||
matrix:Matrix;
|
||||
matrices:[Matrix];
|
||||
simple_position:Vector3DSimple (native_type: "Native::Vector3D", native_inline, native_type_pack_name: "Vector3DSimple");
|
||||
simple_vectors:[Vector3DSimple] (native_type: "Native::Vector3D", native_type_pack_name: "Vector3DSimple");
|
||||
}
|
||||
|
||||
root_type ApplicationData;
|
||||
|
||||
@@ -21,6 +21,8 @@ struct Vector3D;
|
||||
|
||||
struct Vector3DAlt;
|
||||
|
||||
struct Vector3DSimple;
|
||||
|
||||
struct Matrix;
|
||||
struct MatrixBuilder;
|
||||
|
||||
@@ -28,6 +30,8 @@ struct ApplicationData;
|
||||
struct ApplicationDataBuilder;
|
||||
struct ApplicationDataT;
|
||||
|
||||
bool operator==(const Vector3DSimple &lhs, const Vector3DSimple &rhs);
|
||||
bool operator!=(const Vector3DSimple &lhs, const Vector3DSimple &rhs);
|
||||
bool operator==(const ApplicationDataT &lhs, const ApplicationDataT &rhs);
|
||||
bool operator!=(const ApplicationDataT &lhs, const ApplicationDataT &rhs);
|
||||
|
||||
@@ -35,6 +39,8 @@ inline const ::flatbuffers::TypeTable *Vector3DTypeTable();
|
||||
|
||||
inline const ::flatbuffers::TypeTable *Vector3DAltTypeTable();
|
||||
|
||||
inline const ::flatbuffers::TypeTable *Vector3DSimpleTypeTable();
|
||||
|
||||
inline const ::flatbuffers::TypeTable *MatrixTypeTable();
|
||||
|
||||
inline const ::flatbuffers::TypeTable *ApplicationDataTypeTable();
|
||||
@@ -121,6 +127,59 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Vector3DAlt FLATBUFFERS_FINAL_CLASS {
|
||||
};
|
||||
FLATBUFFERS_STRUCT_END(Vector3DAlt, 12);
|
||||
|
||||
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Vector3DSimple FLATBUFFERS_FINAL_CLASS {
|
||||
private:
|
||||
float x_;
|
||||
float y_;
|
||||
float z_;
|
||||
|
||||
public:
|
||||
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return Vector3DSimpleTypeTable();
|
||||
}
|
||||
Vector3DSimple()
|
||||
: x_(0),
|
||||
y_(0),
|
||||
z_(0) {
|
||||
}
|
||||
Vector3DSimple(float _x, float _y, float _z)
|
||||
: x_(::flatbuffers::EndianScalar(_x)),
|
||||
y_(::flatbuffers::EndianScalar(_y)),
|
||||
z_(::flatbuffers::EndianScalar(_z)) {
|
||||
}
|
||||
float x() const {
|
||||
return ::flatbuffers::EndianScalar(x_);
|
||||
}
|
||||
void mutate_x(float _x) {
|
||||
::flatbuffers::WriteScalar(&x_, _x);
|
||||
}
|
||||
float y() const {
|
||||
return ::flatbuffers::EndianScalar(y_);
|
||||
}
|
||||
void mutate_y(float _y) {
|
||||
::flatbuffers::WriteScalar(&y_, _y);
|
||||
}
|
||||
float z() const {
|
||||
return ::flatbuffers::EndianScalar(z_);
|
||||
}
|
||||
void mutate_z(float _z) {
|
||||
::flatbuffers::WriteScalar(&z_, _z);
|
||||
}
|
||||
};
|
||||
FLATBUFFERS_STRUCT_END(Vector3DSimple, 12);
|
||||
|
||||
inline bool operator==(const Vector3DSimple &lhs, const Vector3DSimple &rhs) {
|
||||
return
|
||||
(lhs.x() == rhs.x()) &&
|
||||
(lhs.y() == rhs.y()) &&
|
||||
(lhs.z() == rhs.z());
|
||||
}
|
||||
|
||||
inline bool operator!=(const Vector3DSimple &lhs, const Vector3DSimple &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
|
||||
struct Matrix FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef Native::Matrix NativeTableType;
|
||||
typedef MatrixBuilder Builder;
|
||||
@@ -223,6 +282,8 @@ struct ApplicationDataT : public ::flatbuffers::NativeTable {
|
||||
Native::Vector3D position_inline{};
|
||||
std::unique_ptr<Native::Matrix> matrix{};
|
||||
std::vector<std::unique_ptr<Native::Matrix>> matrices{};
|
||||
Native::Vector3D simple_position{};
|
||||
std::vector<Native::Vector3D> simple_vectors{};
|
||||
ApplicationDataT() = default;
|
||||
ApplicationDataT(const ApplicationDataT &o);
|
||||
ApplicationDataT(ApplicationDataT&&) FLATBUFFERS_NOEXCEPT = default;
|
||||
@@ -241,7 +302,9 @@ struct ApplicationData FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
VT_POSITION = 8,
|
||||
VT_POSITION_INLINE = 10,
|
||||
VT_MATRIX = 12,
|
||||
VT_MATRICES = 14
|
||||
VT_MATRICES = 14,
|
||||
VT_SIMPLE_POSITION = 16,
|
||||
VT_SIMPLE_VECTORS = 18
|
||||
};
|
||||
const ::flatbuffers::Vector<const Geometry::Vector3D *> *vectors() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<const Geometry::Vector3D *> *>(VT_VECTORS);
|
||||
@@ -279,6 +342,18 @@ struct ApplicationData FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
::flatbuffers::Vector<::flatbuffers::Offset<Geometry::Matrix>> *mutable_matrices() {
|
||||
return GetPointer<::flatbuffers::Vector<::flatbuffers::Offset<Geometry::Matrix>> *>(VT_MATRICES);
|
||||
}
|
||||
const Geometry::Vector3DSimple *simple_position() const {
|
||||
return GetStruct<const Geometry::Vector3DSimple *>(VT_SIMPLE_POSITION);
|
||||
}
|
||||
Geometry::Vector3DSimple *mutable_simple_position() {
|
||||
return GetStruct<Geometry::Vector3DSimple *>(VT_SIMPLE_POSITION);
|
||||
}
|
||||
const ::flatbuffers::Vector<const Geometry::Vector3DSimple *> *simple_vectors() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<const Geometry::Vector3DSimple *> *>(VT_SIMPLE_VECTORS);
|
||||
}
|
||||
::flatbuffers::Vector<const Geometry::Vector3DSimple *> *mutable_simple_vectors() {
|
||||
return GetPointer<::flatbuffers::Vector<const Geometry::Vector3DSimple *> *>(VT_SIMPLE_VECTORS);
|
||||
}
|
||||
template <bool B = false>
|
||||
bool Verify(::flatbuffers::VerifierTemplate<B> &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
@@ -293,6 +368,9 @@ struct ApplicationData FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
VerifyOffset(verifier, VT_MATRICES) &&
|
||||
verifier.VerifyVector(matrices()) &&
|
||||
verifier.VerifyVectorOfTables(matrices()) &&
|
||||
VerifyField<Geometry::Vector3DSimple>(verifier, VT_SIMPLE_POSITION, 4) &&
|
||||
VerifyOffset(verifier, VT_SIMPLE_VECTORS) &&
|
||||
verifier.VerifyVector(simple_vectors()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
ApplicationDataT *UnPack(const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
@@ -322,6 +400,12 @@ struct ApplicationDataBuilder {
|
||||
void add_matrices(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<Geometry::Matrix>>> matrices) {
|
||||
fbb_.AddOffset(ApplicationData::VT_MATRICES, matrices);
|
||||
}
|
||||
void add_simple_position(const Geometry::Vector3DSimple *simple_position) {
|
||||
fbb_.AddStruct(ApplicationData::VT_SIMPLE_POSITION, simple_position);
|
||||
}
|
||||
void add_simple_vectors(::flatbuffers::Offset<::flatbuffers::Vector<const Geometry::Vector3DSimple *>> simple_vectors) {
|
||||
fbb_.AddOffset(ApplicationData::VT_SIMPLE_VECTORS, simple_vectors);
|
||||
}
|
||||
explicit ApplicationDataBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
@@ -340,8 +424,12 @@ inline ::flatbuffers::Offset<ApplicationData> CreateApplicationData(
|
||||
const Geometry::Vector3D *position = nullptr,
|
||||
const Geometry::Vector3D *position_inline = nullptr,
|
||||
::flatbuffers::Offset<Geometry::Matrix> matrix = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<Geometry::Matrix>>> matrices = 0) {
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<Geometry::Matrix>>> matrices = 0,
|
||||
const Geometry::Vector3DSimple *simple_position = nullptr,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<const Geometry::Vector3DSimple *>> simple_vectors = 0) {
|
||||
ApplicationDataBuilder builder_(_fbb);
|
||||
builder_.add_simple_vectors(simple_vectors);
|
||||
builder_.add_simple_position(simple_position);
|
||||
builder_.add_matrices(matrices);
|
||||
builder_.add_matrix(matrix);
|
||||
builder_.add_position_inline(position_inline);
|
||||
@@ -358,10 +446,13 @@ inline ::flatbuffers::Offset<ApplicationData> CreateApplicationDataDirect(
|
||||
const Geometry::Vector3D *position = nullptr,
|
||||
const Geometry::Vector3D *position_inline = nullptr,
|
||||
::flatbuffers::Offset<Geometry::Matrix> matrix = 0,
|
||||
const std::vector<::flatbuffers::Offset<Geometry::Matrix>> *matrices = nullptr) {
|
||||
const std::vector<::flatbuffers::Offset<Geometry::Matrix>> *matrices = nullptr,
|
||||
const Geometry::Vector3DSimple *simple_position = nullptr,
|
||||
const std::vector<Geometry::Vector3DSimple> *simple_vectors = nullptr) {
|
||||
auto vectors__ = vectors ? _fbb.CreateVectorOfStructs<Geometry::Vector3D>(*vectors) : 0;
|
||||
auto vectors_alt__ = vectors_alt ? _fbb.CreateVectorOfStructs<Geometry::Vector3DAlt>(*vectors_alt) : 0;
|
||||
auto matrices__ = matrices ? _fbb.CreateVector<::flatbuffers::Offset<Geometry::Matrix>>(*matrices) : 0;
|
||||
auto simple_vectors__ = simple_vectors ? _fbb.CreateVectorOfStructs<Geometry::Vector3DSimple>(*simple_vectors) : 0;
|
||||
return Geometry::CreateApplicationData(
|
||||
_fbb,
|
||||
vectors__,
|
||||
@@ -369,7 +460,9 @@ inline ::flatbuffers::Offset<ApplicationData> CreateApplicationDataDirect(
|
||||
position,
|
||||
position_inline,
|
||||
matrix,
|
||||
matrices__);
|
||||
matrices__,
|
||||
simple_position,
|
||||
simple_vectors__);
|
||||
}
|
||||
|
||||
::flatbuffers::Offset<ApplicationData> CreateApplicationData(::flatbuffers::FlatBufferBuilder &_fbb, const ApplicationDataT *_o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
@@ -392,7 +485,9 @@ inline bool operator==(const ApplicationDataT &lhs, const ApplicationDataT &rhs)
|
||||
((lhs.position == rhs.position) || (lhs.position && rhs.position && *lhs.position == *rhs.position)) &&
|
||||
(lhs.position_inline == rhs.position_inline) &&
|
||||
((lhs.matrix == rhs.matrix) || (lhs.matrix && rhs.matrix && *lhs.matrix == *rhs.matrix)) &&
|
||||
(lhs.matrices.size() == rhs.matrices.size() && std::equal(lhs.matrices.cbegin(), lhs.matrices.cend(), rhs.matrices.cbegin(), [](std::unique_ptr<Native::Matrix> const &a, std::unique_ptr<Native::Matrix> const &b) { return (a == b) || (a && b && *a == *b); }));
|
||||
(lhs.matrices.size() == rhs.matrices.size() && std::equal(lhs.matrices.cbegin(), lhs.matrices.cend(), rhs.matrices.cbegin(), [](std::unique_ptr<Native::Matrix> const &a, std::unique_ptr<Native::Matrix> const &b) { return (a == b) || (a && b && *a == *b); })) &&
|
||||
(lhs.simple_position == rhs.simple_position) &&
|
||||
(lhs.simple_vectors == rhs.simple_vectors);
|
||||
}
|
||||
|
||||
inline bool operator!=(const ApplicationDataT &lhs, const ApplicationDataT &rhs) {
|
||||
@@ -405,7 +500,9 @@ inline ApplicationDataT::ApplicationDataT(const ApplicationDataT &o)
|
||||
vectors_alt(o.vectors_alt),
|
||||
position((o.position) ? new Native::Vector3D(*o.position) : nullptr),
|
||||
position_inline(o.position_inline),
|
||||
matrix((o.matrix) ? new Native::Matrix(*o.matrix) : nullptr) {
|
||||
matrix((o.matrix) ? new Native::Matrix(*o.matrix) : nullptr),
|
||||
simple_position(o.simple_position),
|
||||
simple_vectors(o.simple_vectors) {
|
||||
matrices.reserve(o.matrices.size());
|
||||
for (const auto &matrices_ : o.matrices) { matrices.emplace_back((matrices_) ? new Native::Matrix(*matrices_) : nullptr); }
|
||||
}
|
||||
@@ -417,6 +514,8 @@ inline ApplicationDataT &ApplicationDataT::operator=(ApplicationDataT o) FLATBUF
|
||||
std::swap(position_inline, o.position_inline);
|
||||
std::swap(matrix, o.matrix);
|
||||
std::swap(matrices, o.matrices);
|
||||
std::swap(simple_position, o.simple_position);
|
||||
std::swap(simple_vectors, o.simple_vectors);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -435,6 +534,8 @@ inline void ApplicationData::UnPackTo(ApplicationDataT *_o, const ::flatbuffers:
|
||||
{ auto _e = position_inline(); if (_e) _o->position_inline = ::flatbuffers::UnPack(*_e); }
|
||||
{ auto _e = matrix(); if (_e) { if(_o->matrix) { _e->UnPackTo(_o->matrix.get(), _resolver); } else { _o->matrix = std::unique_ptr<Native::Matrix>(_e->UnPack(_resolver)); } } else if (_o->matrix) { _o->matrix.reset(); } }
|
||||
{ auto _e = matrices(); if (_e) { _o->matrices.resize(_e->size()); for (::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { if(_o->matrices[_i]) { _e->Get(_i)->UnPackTo(_o->matrices[_i].get(), _resolver); } else { _o->matrices[_i] = std::unique_ptr<Native::Matrix>(_e->Get(_i)->UnPack(_resolver)); } } } else { _o->matrices.resize(0); } }
|
||||
{ auto _e = simple_position(); if (_e) _o->simple_position = ::flatbuffers::UnPackVector3DSimple(*_e); }
|
||||
{ auto _e = simple_vectors(); if (_e) { _o->simple_vectors.resize(_e->size()); for (::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->simple_vectors[_i] = ::flatbuffers::UnPackVector3DSimple(*_e->Get(_i)); } } else { _o->simple_vectors.resize(0); } }
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<ApplicationData> CreateApplicationData(::flatbuffers::FlatBufferBuilder &_fbb, const ApplicationDataT *_o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
@@ -451,6 +552,8 @@ inline ::flatbuffers::Offset<ApplicationData> ApplicationData::Pack(::flatbuffer
|
||||
auto _position_inline = ::flatbuffers::Pack(_o->position_inline);
|
||||
auto _matrix = _o->matrix ? CreateMatrix(_fbb, _o->matrix.get(), _rehasher) : 0;
|
||||
auto _matrices = _o->matrices.size() ? _fbb.CreateVector<::flatbuffers::Offset<Geometry::Matrix>> (_o->matrices.size(), [](size_t i, _VectorArgs *__va) { return CreateMatrix(*__va->__fbb, __va->__o->matrices[i].get(), __va->__rehasher); }, &_va ) : 0;
|
||||
auto _simple_position = ::flatbuffers::PackVector3DSimple(_o->simple_position);
|
||||
auto _simple_vectors = _o->simple_vectors.size() ? _fbb.CreateVectorOfNativeStructs<Geometry::Vector3DSimple, Native::Vector3D>(_o->simple_vectors, ::flatbuffers::PackVector3DSimple) : 0;
|
||||
return Geometry::CreateApplicationData(
|
||||
_fbb,
|
||||
_vectors,
|
||||
@@ -458,7 +561,9 @@ inline ::flatbuffers::Offset<ApplicationData> ApplicationData::Pack(::flatbuffer
|
||||
_o->position ? &_position : nullptr,
|
||||
&_position_inline,
|
||||
_matrix,
|
||||
_matrices);
|
||||
_matrices,
|
||||
&_simple_position,
|
||||
_simple_vectors);
|
||||
}
|
||||
|
||||
inline const ::flatbuffers::TypeTable *Vector3DTypeTable() {
|
||||
@@ -497,6 +602,24 @@ inline const ::flatbuffers::TypeTable *Vector3DAltTypeTable() {
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const ::flatbuffers::TypeTable *Vector3DSimpleTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_FLOAT, 0, -1 },
|
||||
{ ::flatbuffers::ET_FLOAT, 0, -1 },
|
||||
{ ::flatbuffers::ET_FLOAT, 0, -1 }
|
||||
};
|
||||
static const int64_t values[] = { 0, 4, 8, 12 };
|
||||
static const char * const names[] = {
|
||||
"x",
|
||||
"y",
|
||||
"z"
|
||||
};
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_STRUCT, 3, type_codes, nullptr, nullptr, values, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const ::flatbuffers::TypeTable *MatrixTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_INT, 0, -1 },
|
||||
@@ -521,12 +644,15 @@ inline const ::flatbuffers::TypeTable *ApplicationDataTypeTable() {
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 0 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 0 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 2 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 1, 2 }
|
||||
{ ::flatbuffers::ET_SEQUENCE, 1, 2 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 3 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 1, 3 }
|
||||
};
|
||||
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||
Geometry::Vector3DTypeTable,
|
||||
Geometry::Vector3DAltTypeTable,
|
||||
Geometry::MatrixTypeTable
|
||||
Geometry::MatrixTypeTable,
|
||||
Geometry::Vector3DSimpleTypeTable
|
||||
};
|
||||
static const char * const names[] = {
|
||||
"vectors",
|
||||
@@ -534,10 +660,12 @@ inline const ::flatbuffers::TypeTable *ApplicationDataTypeTable() {
|
||||
"position",
|
||||
"position_inline",
|
||||
"matrix",
|
||||
"matrices"
|
||||
"matrices",
|
||||
"simple_position",
|
||||
"simple_vectors"
|
||||
};
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_TABLE, 6, type_codes, type_refs, nullptr, nullptr, names
|
||||
::flatbuffers::ST_TABLE, 8, type_codes, type_refs, nullptr, nullptr, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,15 @@ Geometry::Vector3DAlt PackVector3DAlt(const Native::Vector3D& obj) {
|
||||
const Native::Vector3D UnPackVector3DAlt(const Geometry::Vector3DAlt& obj) {
|
||||
return Native::Vector3D(obj.a(), obj.b(), obj.c());
|
||||
}
|
||||
|
||||
Geometry::Vector3DSimple PackVector3DSimple(const Native::Vector3D& obj) {
|
||||
return Geometry::Vector3DSimple(obj.x, obj.y, obj.z);
|
||||
}
|
||||
|
||||
const Native::Vector3D UnPackVector3DSimple(
|
||||
const Geometry::Vector3DSimple& obj) {
|
||||
return Native::Vector3D(obj.x(), obj.y(), obj.z());
|
||||
}
|
||||
} // namespace flatbuffers
|
||||
|
||||
namespace Geometry {
|
||||
|
||||
@@ -48,6 +48,7 @@ struct Matrix {
|
||||
namespace Geometry {
|
||||
struct Vector3D;
|
||||
struct Vector3DAlt;
|
||||
struct Vector3DSimple;
|
||||
} // namespace Geometry
|
||||
|
||||
namespace flatbuffers {
|
||||
@@ -55,6 +56,8 @@ Geometry::Vector3D Pack(const Native::Vector3D& obj);
|
||||
const Native::Vector3D UnPack(const Geometry::Vector3D& obj);
|
||||
Geometry::Vector3DAlt PackVector3DAlt(const Native::Vector3D& obj);
|
||||
const Native::Vector3D UnPackVector3DAlt(const Geometry::Vector3DAlt& obj);
|
||||
Geometry::Vector3DSimple PackVector3DSimple(const Native::Vector3D& obj);
|
||||
const Native::Vector3D UnPackVector3DSimple(const Geometry::Vector3DSimple& obj);
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // VECTOR3D_PACK_H
|
||||
|
||||
@@ -2200,27 +2200,18 @@ def make_monster_from_generated_code(
|
||||
test2 = b.CreateString('test2')
|
||||
fred = b.CreateString('Fred')
|
||||
|
||||
_MONSTER.MonsterStartInventoryVector(b, 5)
|
||||
b.PrependByte(4)
|
||||
b.PrependByte(3)
|
||||
b.PrependByte(2)
|
||||
b.PrependByte(1)
|
||||
b.PrependByte(0)
|
||||
inv = b.EndVector()
|
||||
inv = _MONSTER.MonsterCreateInventoryVector(b, range(5))
|
||||
|
||||
_MONSTER.MonsterStart(b)
|
||||
_MONSTER.MonsterAddName(b, fred)
|
||||
mon2 = _MONSTER.MonsterEnd(b)
|
||||
|
||||
_MONSTER.MonsterStartTest4Vector(b, 2)
|
||||
_TEST.CreateTest(b, 10, 20)
|
||||
_TEST.CreateTest(b, 30, 40)
|
||||
test4 = b.EndVector()
|
||||
test4_structs = (_TEST.TestT(10, 20), _TEST.TestT(30, 40))
|
||||
test4 = _MONSTER.MonsterCreateTest4Vector(b, test4_structs)
|
||||
|
||||
_MONSTER.MonsterStartTestarrayofstringVector(b, 2)
|
||||
b.PrependUOffsetTRelative(test2)
|
||||
b.PrependUOffsetTRelative(test1)
|
||||
testArrayOfString = b.EndVector()
|
||||
testArrayOfString = _MONSTER.MonsterCreateTestarrayofstringVector(
|
||||
b, [test1, test2]
|
||||
)
|
||||
|
||||
_MONSTER.MonsterStartVectorOfLongsVector(b, 5)
|
||||
b.PrependInt64(100000000)
|
||||
|
||||
@@ -30,14 +30,6 @@ static A: TrackingAllocator = TrackingAllocator;
|
||||
// import the flatbuffers generated code:
|
||||
extern crate flatbuffers;
|
||||
|
||||
#[allow(dead_code, unused_imports, clippy::all)]
|
||||
#[path = "../../include_test1/mod.rs"]
|
||||
pub mod include_test1_generated;
|
||||
|
||||
#[allow(dead_code, unused_imports, clippy::all)]
|
||||
#[path = "../../include_test2/mod.rs"]
|
||||
pub mod include_test2_generated;
|
||||
|
||||
#[allow(dead_code, unused_imports, clippy::all)]
|
||||
#[path = "../../monster_test/mod.rs"]
|
||||
mod monster_test_generated;
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
#![allow(clippy::derivable_impls, clippy::all)]
|
||||
extern crate flatbuffers;
|
||||
|
||||
#[allow(dead_code, unused_imports)]
|
||||
#[path = "../../include_test1/mod.rs"]
|
||||
pub mod include_test1_generated;
|
||||
|
||||
#[allow(dead_code, unused_imports)]
|
||||
#[path = "../../include_test2/mod.rs"]
|
||||
pub mod include_test2_generated;
|
||||
|
||||
#[allow(dead_code, unused_imports, clippy::approx_constant)]
|
||||
#[path = "../../monster_test/mod.rs"]
|
||||
mod monster_test_generated;
|
||||
|
||||
15
tests/rust_usage_test/tests/include_test.rs
Normal file
15
tests/rust_usage_test/tests/include_test.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
#[allow(dead_code, unused_imports, clippy::all)]
|
||||
#[path = "../../include_test1/mod.rs"]
|
||||
mod include_test1_generated;
|
||||
|
||||
#[allow(dead_code, unused_imports, clippy::all)]
|
||||
#[path = "../../include_test2/mod.rs"]
|
||||
mod include_test2_generated;
|
||||
|
||||
#[allow(dead_code, unused_imports, clippy::all)]
|
||||
#[path = "../../include_test1_generated.rs"]
|
||||
mod include_test1_standalone;
|
||||
|
||||
#[allow(dead_code, unused_imports, clippy::all)]
|
||||
#[path = "../../include_test2_generated.rs"]
|
||||
mod include_test2_standalone;
|
||||
@@ -48,14 +48,6 @@ mod flexbuffers_tests;
|
||||
mod more_defaults_test;
|
||||
mod optional_scalars_test;
|
||||
|
||||
#[allow(dead_code, unused_imports, clippy::all)]
|
||||
#[path = "../../include_test1/mod.rs"]
|
||||
pub mod include_test1_generated;
|
||||
|
||||
#[allow(dead_code, unused_imports, clippy::all)]
|
||||
#[path = "../../include_test2/mod.rs"]
|
||||
pub mod include_test2_generated;
|
||||
|
||||
#[allow(dead_code, unused_imports, clippy::all)]
|
||||
#[path = "../../namespace_test/mod.rs"]
|
||||
pub mod namespace_test_generated;
|
||||
|
||||
164
tests/rust_usage_test/tests/vtable_zeroed_test.rs
Normal file
164
tests/rust_usage_test/tests/vtable_zeroed_test.rs
Normal file
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright 2024 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.
|
||||
*/
|
||||
|
||||
//! Regression test for https://github.com/google/flatbuffers/issues/8894
|
||||
//!
|
||||
//! Tests that vtable memory is properly zeroed when building FlatBuffers.
|
||||
|
||||
extern crate alloc;
|
||||
extern crate flatbuffers;
|
||||
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
use core::convert::Infallible;
|
||||
use core::cmp::max;
|
||||
use core::ops::{Deref, DerefMut};
|
||||
use core::ptr::write_bytes;
|
||||
|
||||
use flatbuffers::{Allocator, FlatBufferBuilder};
|
||||
|
||||
/// Custom allocator that pre-fills buffer with garbage (0xAA) to detect
|
||||
/// uninitialized memory bugs.
|
||||
struct GarbageFilledAllocator(Vec<u8>);
|
||||
|
||||
impl GarbageFilledAllocator {
|
||||
fn new(size: usize) -> Self {
|
||||
Self(vec![0xAA; size])
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for GarbageFilledAllocator {
|
||||
type Target = [u8];
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for GarbageFilledAllocator {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
// SAFETY: grow_downwards properly moves data and the new space is filled with garbage
|
||||
// (intentionally, to detect bugs where code assumes zeroed memory)
|
||||
unsafe impl Allocator for GarbageFilledAllocator {
|
||||
type Error = Infallible;
|
||||
|
||||
fn grow_downwards(&mut self) -> Result<(), Self::Error> {
|
||||
let old_len = self.0.len();
|
||||
let new_len = max(1, old_len * 2);
|
||||
|
||||
// Resize and fill new space with garbage
|
||||
self.0.resize(new_len, 0xAA);
|
||||
|
||||
if new_len == 1 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Move old data to the end
|
||||
let middle = new_len / 2;
|
||||
{
|
||||
let (left, right) = &mut self.0[..].split_at_mut(middle);
|
||||
right.copy_from_slice(left);
|
||||
}
|
||||
// Fill old space with garbage (NOT zeros)
|
||||
{
|
||||
let ptr = self.0[..middle].as_mut_ptr();
|
||||
unsafe {
|
||||
write_bytes(ptr, 0xAA, middle);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.0.len()
|
||||
}
|
||||
}
|
||||
|
||||
/// Regression test for https://github.com/google/flatbuffers/issues/8894
|
||||
///
|
||||
/// The bug: write_vtable() called make_space() which only reserves memory
|
||||
/// but doesn't zero it. If the allocator's buffer contains garbage data,
|
||||
/// vtable entries for fields with default values would contain garbage
|
||||
/// instead of zero (which indicates "use default").
|
||||
///
|
||||
/// This test uses a garbage-filled allocator to detect if vtable memory
|
||||
/// is properly zeroed before being written.
|
||||
#[test]
|
||||
fn test_vtable_zeroed_with_garbage_allocator() {
|
||||
// Create a builder with garbage-filled allocator
|
||||
let allocator = GarbageFilledAllocator::new(256);
|
||||
let mut builder: FlatBufferBuilder<GarbageFilledAllocator> =
|
||||
FlatBufferBuilder::new_in(allocator);
|
||||
|
||||
// Start a table
|
||||
let table_start = builder.start_table();
|
||||
|
||||
// Set a field at a HIGH slot ID (14) to force a larger vtable.
|
||||
// This leaves slots 4, 6, 8, 10, 12 unset (should be zero).
|
||||
// VTable layout: [vtable_size:2][table_size:2][field0:2][field1:2][field2:2][field3:2][field4:2][field5:2]
|
||||
// Offsets: 0 2 4 6 8 10 12 14
|
||||
builder.push_slot::<u32>(14, 42, 0); // Set field 5 (at vtable offset 14) to 42
|
||||
|
||||
// End the table - this calls write_vtable()
|
||||
let table_end = builder.end_table(table_start);
|
||||
|
||||
// Finish the buffer
|
||||
builder.finish(table_end, None);
|
||||
|
||||
let data = builder.finished_data();
|
||||
|
||||
// Read the root table offset (first 4 bytes, little-endian)
|
||||
let root_offset = u32::from_le_bytes([data[0], data[1], data[2], data[3]]) as usize;
|
||||
let table_pos = root_offset;
|
||||
|
||||
// Read the vtable offset (signed, at table position)
|
||||
let vtable_offset = i32::from_le_bytes([
|
||||
data[table_pos],
|
||||
data[table_pos + 1],
|
||||
data[table_pos + 2],
|
||||
data[table_pos + 3],
|
||||
]);
|
||||
let vtable_pos = (table_pos as i32 - vtable_offset) as usize;
|
||||
|
||||
// Read vtable size (first 2 bytes of vtable)
|
||||
let vtable_size = u16::from_le_bytes([data[vtable_pos], data[vtable_pos + 1]]) as usize;
|
||||
|
||||
// Verify vtable structure is as expected (16 bytes total for 6 fields + header)
|
||||
assert_eq!(
|
||||
vtable_size, 16,
|
||||
"VTable should be 16 bytes (4 header + 6*2 fields)"
|
||||
);
|
||||
|
||||
// Check that unset fields (at offsets 4, 6, 8, 10, 12) are zero.
|
||||
// Only field at offset 14 was set.
|
||||
// If the bug exists, unset fields would be 0xAAAA instead of 0.
|
||||
for i in [4_usize, 6, 8, 10, 12] {
|
||||
let field_offset = u16::from_le_bytes([data[vtable_pos + i], data[vtable_pos + i + 1]]);
|
||||
assert_eq!(
|
||||
field_offset, 0,
|
||||
"Vtable entry at offset {} should be 0 (default), but was 0x{:04X}. \
|
||||
This indicates uninitialized vtable memory (issue #8894).",
|
||||
i, field_offset
|
||||
);
|
||||
}
|
||||
|
||||
// Verify the field we DID set has a non-zero offset
|
||||
let field5_offset = u16::from_le_bytes([data[vtable_pos + 14], data[vtable_pos + 14 + 1]]);
|
||||
assert_ne!(field5_offset, 0, "Field 5 should have a non-zero offset");
|
||||
}
|
||||
@@ -2,61 +2,56 @@
|
||||
|
||||
# namespace: example
|
||||
|
||||
from typing import Any
|
||||
import flatbuffers
|
||||
|
||||
|
||||
class HelloRequest(object):
|
||||
__slots__ = ['_tab']
|
||||
__slots__ = ['_tab']
|
||||
|
||||
@classmethod
|
||||
def GetRootAs(cls, buf, offset: int = 0):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
|
||||
x = HelloRequest()
|
||||
x.Init(buf, n + offset)
|
||||
return x
|
||||
@classmethod
|
||||
def GetRootAs(cls, buf, offset=0):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
|
||||
x = HelloRequest()
|
||||
x.Init(buf, n + offset)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def GetRootAsHelloRequest(cls, buf, offset=0):
|
||||
"""This method is deprecated. Please switch to GetRootAs."""
|
||||
return cls.GetRootAs(buf, offset)
|
||||
@classmethod
|
||||
def GetRootAsHelloRequest(cls, buf, offset=0):
|
||||
"""This method is deprecated. Please switch to GetRootAs."""
|
||||
return cls.GetRootAs(buf, offset)
|
||||
# HelloRequest
|
||||
def Init(self, buf, pos):
|
||||
self._tab = flatbuffers.table.Table(buf, pos)
|
||||
|
||||
# HelloRequest
|
||||
def Init(self, buf: bytes, pos: int):
|
||||
self._tab = flatbuffers.table.Table(buf, pos)
|
||||
def HelloRequestStart(builder):
|
||||
builder.StartObject(0)
|
||||
|
||||
def HelloRequestEnd(builder):
|
||||
return builder.EndObject()
|
||||
|
||||
def HelloRequestStart(builder: flatbuffers.Builder):
|
||||
builder.StartObject(0)
|
||||
|
||||
|
||||
def HelloRequestEnd(builder: flatbuffers.Builder) -> int:
|
||||
return builder.EndObject()
|
||||
|
||||
|
||||
class HelloResponse(object):
|
||||
__slots__ = ['_tab']
|
||||
__slots__ = ['_tab']
|
||||
|
||||
@classmethod
|
||||
def GetRootAs(cls, buf, offset: int = 0):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
|
||||
x = HelloResponse()
|
||||
x.Init(buf, n + offset)
|
||||
return x
|
||||
@classmethod
|
||||
def GetRootAs(cls, buf, offset=0):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
|
||||
x = HelloResponse()
|
||||
x.Init(buf, n + offset)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def GetRootAsHelloResponse(cls, buf, offset=0):
|
||||
"""This method is deprecated. Please switch to GetRootAs."""
|
||||
return cls.GetRootAs(buf, offset)
|
||||
@classmethod
|
||||
def GetRootAsHelloResponse(cls, buf, offset=0):
|
||||
"""This method is deprecated. Please switch to GetRootAs."""
|
||||
return cls.GetRootAs(buf, offset)
|
||||
# HelloResponse
|
||||
def Init(self, buf, pos):
|
||||
self._tab = flatbuffers.table.Table(buf, pos)
|
||||
|
||||
# HelloResponse
|
||||
def Init(self, buf: bytes, pos: int):
|
||||
self._tab = flatbuffers.table.Table(buf, pos)
|
||||
def HelloResponseStart(builder):
|
||||
builder.StartObject(0)
|
||||
|
||||
def HelloResponseEnd(builder):
|
||||
return builder.EndObject()
|
||||
|
||||
|
||||
def HelloResponseStart(builder: flatbuffers.Builder):
|
||||
builder.StartObject(0)
|
||||
|
||||
|
||||
def HelloResponseEnd(builder: flatbuffers.Builder) -> int:
|
||||
return builder.EndObject()
|
||||
|
||||
107
tests/test.cpp
107
tests/test.cpp
@@ -63,7 +63,9 @@
|
||||
#include "flexbuffers_test.h"
|
||||
#include "is_quiet_nan.h"
|
||||
#include "monster_test_bfbs_generated.h" // Generated using --bfbs-comments --bfbs-builtins --cpp --bfbs-gen-embed
|
||||
#include "cpp_vec_type_test_generated.h"
|
||||
#include "native_type_test_generated.h"
|
||||
#include "cpp_vec_type_native_type_test_generated.h"
|
||||
#include "test_assert.h"
|
||||
#include "util_test.h"
|
||||
#include "vector_table_naked_ptr_test.h"
|
||||
@@ -929,6 +931,12 @@ void NativeTypeTest() {
|
||||
Native::Vector3D(20 * i + 0.1f, 20 * i + 0.2f, 20 * i + 0.3f));
|
||||
}
|
||||
|
||||
src_data.simple_position = Native::Vector3D(7.0f, 8.0f, 9.0f);
|
||||
for (int i = 0; i < N; ++i) {
|
||||
src_data.simple_vectors.push_back(
|
||||
Native::Vector3D(30 * i + 0.1f, 30 * i + 0.2f, 30 * i + 0.3f));
|
||||
}
|
||||
|
||||
src_data.matrix = std::unique_ptr<Native::Matrix>(new Native::Matrix(1, 2));
|
||||
src_data.matrix->values = {3, 4};
|
||||
|
||||
@@ -963,6 +971,17 @@ void NativeTypeTest() {
|
||||
TEST_EQ(v2.z, 20 * i + 0.3f);
|
||||
}
|
||||
|
||||
TEST_EQ(dstDataT->simple_position.x, 7.0f);
|
||||
TEST_EQ(dstDataT->simple_position.y, 8.0f);
|
||||
TEST_EQ(dstDataT->simple_position.z, 9.0f);
|
||||
|
||||
for (int i = 0; i < N; ++i) {
|
||||
const Native::Vector3D& sv = dstDataT->simple_vectors[i];
|
||||
TEST_EQ(sv.x, 30 * i + 0.1f);
|
||||
TEST_EQ(sv.y, 30 * i + 0.2f);
|
||||
TEST_EQ(sv.z, 30 * i + 0.3f);
|
||||
}
|
||||
|
||||
TEST_EQ(dstDataT->matrix->rows, 1);
|
||||
TEST_EQ(dstDataT->matrix->columns, 2);
|
||||
TEST_EQ(dstDataT->matrix->values[0], 3);
|
||||
@@ -978,6 +997,92 @@ void NativeTypeTest() {
|
||||
}
|
||||
}
|
||||
|
||||
void CppVecTypeTest() {
|
||||
static_assert(
|
||||
std::is_same<decltype(CppVecTest::DataT{}.values),
|
||||
CppVecTest::CustomVec<int32_t>>::value,
|
||||
"values should be CustomVec<int32_t>");
|
||||
static_assert(
|
||||
std::is_same<decltype(CppVecTest::DataT{}.regular),
|
||||
std::vector<int32_t>>::value,
|
||||
"regular should be std::vector<int32_t>");
|
||||
|
||||
CppVecTest::DataT src;
|
||||
src.values.push_back(10);
|
||||
src.values.push_back(20);
|
||||
src.values.push_back(30);
|
||||
|
||||
auto item = flatbuffers::unique_ptr<CppVecTest::ItemT>(new CppVecTest::ItemT());
|
||||
item->id = 42;
|
||||
item->value = 1.5f;
|
||||
src.items.push_back(std::move(item));
|
||||
|
||||
src.strs.push_back("hello");
|
||||
src.strs.push_back("world");
|
||||
|
||||
flatbuffers::FlatBufferBuilder fbb;
|
||||
fbb.Finish(CppVecTest::Data::Pack(fbb, &src));
|
||||
|
||||
auto dst = CppVecTest::UnPackData(fbb.GetBufferPointer());
|
||||
|
||||
TEST_EQ(dst->values.size(), 3U);
|
||||
TEST_EQ(dst->values[0], 10);
|
||||
TEST_EQ(dst->values[1], 20);
|
||||
TEST_EQ(dst->values[2], 30);
|
||||
|
||||
TEST_EQ(dst->items.size(), 1U);
|
||||
TEST_EQ(dst->items[0]->id, 42);
|
||||
TEST_EQ(dst->items[0]->value, 1.5f);
|
||||
|
||||
TEST_EQ(dst->strs.size(), 2U);
|
||||
TEST_EQ(dst->strs[0], std::string("hello"));
|
||||
TEST_EQ(dst->strs[1], std::string("world"));
|
||||
|
||||
TEST_EQ(dst->regular.size(), 0U);
|
||||
TEST_ASSERT(*dst == *dst);
|
||||
}
|
||||
|
||||
void CppVecTypeNativeTypeTest() {
|
||||
// Verify that combining cpp_vec_type + native_type on a vector of structs
|
||||
// produces the correct container type in the NativeTable.
|
||||
static_assert(
|
||||
std::is_same<
|
||||
decltype(CppVecNativeTypeTest::ContainerT{}.points),
|
||||
CppVecNativeTypeTest::CustomVec<
|
||||
CppVecNativeTypeTest::Native::Vec3>>::value,
|
||||
"points should be CustomVec<Native::Vec3>");
|
||||
static_assert(
|
||||
std::is_same<decltype(CppVecNativeTypeTest::ContainerT{}.bytes),
|
||||
CppVecNativeTypeTest::CustomVec<uint8_t>>::value,
|
||||
"bytes should be CustomVec<uint8_t>");
|
||||
|
||||
const int N = 3;
|
||||
CppVecNativeTypeTest::ContainerT src;
|
||||
for (int i = 0; i < N; ++i) {
|
||||
src.points.push_back(
|
||||
CppVecNativeTypeTest::Native::Vec3(1.0f * i, 2.0f * i, 3.0f * i));
|
||||
src.bytes.push_back(static_cast<uint8_t>(i * 10));
|
||||
}
|
||||
|
||||
flatbuffers::FlatBufferBuilder fbb;
|
||||
fbb.Finish(CppVecNativeTypeTest::Container::Pack(fbb, &src));
|
||||
|
||||
auto dst =
|
||||
CppVecNativeTypeTest::UnPackContainer(fbb.GetBufferPointer());
|
||||
|
||||
TEST_EQ(dst->points.size(), static_cast<size_t>(N));
|
||||
for (int i = 0; i < N; ++i) {
|
||||
TEST_EQ(dst->points[i].x, 1.0f * i);
|
||||
TEST_EQ(dst->points[i].y, 2.0f * i);
|
||||
TEST_EQ(dst->points[i].z, 3.0f * i);
|
||||
}
|
||||
|
||||
TEST_EQ(dst->bytes.size(), static_cast<size_t>(N));
|
||||
for (int i = 0; i < N; ++i) {
|
||||
TEST_EQ(dst->bytes[i], static_cast<uint8_t>(i * 10));
|
||||
}
|
||||
}
|
||||
|
||||
// Guard against -Wunused-function on platforms without file tests.
|
||||
#ifndef FLATBUFFERS_NO_FILE_TESTS
|
||||
// VS10 does not support typed enums, exclude from tests
|
||||
@@ -1813,6 +1918,8 @@ int FlatBufferTests(const std::string& tests_data_path) {
|
||||
InvalidFloatTest();
|
||||
FixedLengthArrayTest();
|
||||
NativeTypeTest();
|
||||
CppVecTypeTest();
|
||||
CppVecTypeNativeTypeTest();
|
||||
OptionalScalarsTest();
|
||||
ParseFlexbuffersFromJsonWithNullTest();
|
||||
FlatbuffersSpanTest();
|
||||
|
||||
60
tests/ts/JavaScriptUndefinedForOptionals.js
Normal file
60
tests/ts/JavaScriptUndefinedForOptionals.js
Normal file
@@ -0,0 +1,60 @@
|
||||
import assert from 'assert'
|
||||
import * as flatbuffers from 'flatbuffers'
|
||||
|
||||
import optional_scalars from './ts-undefined-for-optionals/optional_scalars_generated.cjs'
|
||||
|
||||
const { ScalarStuff, ScalarStuffT } = optional_scalars.optional_scalars;
|
||||
|
||||
function testScalarStuffBuf(scalarStuff) {
|
||||
assert.strictEqual(scalarStuff.justI8(), -1);
|
||||
assert.strictEqual(scalarStuff.maybeI8(), undefined);
|
||||
assert.strictEqual(scalarStuff.defaultI8(), 42);
|
||||
assert.strictEqual(scalarStuff.justU8(), 1);
|
||||
assert.strictEqual(scalarStuff.maybeU8(), undefined);
|
||||
assert.strictEqual(scalarStuff.defaultU8(), 42);
|
||||
}
|
||||
|
||||
function testScalarStuffUnpack(scalarStuff) {
|
||||
assert.strictEqual(scalarStuff.justI8, -1);
|
||||
assert.strictEqual(scalarStuff.maybeI8, undefined);
|
||||
assert.strictEqual(scalarStuff.defaultI8, 42);
|
||||
assert.strictEqual(scalarStuff.justU8, 1);
|
||||
assert.strictEqual(scalarStuff.maybeU8, undefined);
|
||||
assert.strictEqual(scalarStuff.defaultU8, 42);
|
||||
}
|
||||
|
||||
function createScalarStuff(fbb) {
|
||||
ScalarStuff.startScalarStuff(fbb);
|
||||
ScalarStuff.addJustI8(fbb, -1);
|
||||
ScalarStuff.addJustU8(fbb, 1);
|
||||
var offset = ScalarStuff.endScalarStuff(fbb);
|
||||
ScalarStuff.finishScalarStuffBuffer(fbb, offset);
|
||||
}
|
||||
|
||||
function main() {
|
||||
var fbb = new flatbuffers.Builder();
|
||||
|
||||
createScalarStuff(fbb);
|
||||
|
||||
var buf = new flatbuffers.ByteBuffer(fbb.asUint8Array());
|
||||
var scalarStuff = ScalarStuff.getRootAsScalarStuff(buf);
|
||||
|
||||
testScalarStuffBuf(scalarStuff);
|
||||
|
||||
testScalarStuffUnpack(scalarStuff.unpack());
|
||||
|
||||
var scalarStuff_to = new ScalarStuffT();
|
||||
scalarStuff.unpackTo(scalarStuff_to);
|
||||
|
||||
testScalarStuffUnpack(scalarStuff_to);
|
||||
|
||||
fbb.clear();
|
||||
ScalarStuff.finishScalarStuffBuffer(fbb, scalarStuff_to.pack(fbb));
|
||||
var unpackBuf = new flatbuffers.ByteBuffer(fbb.asUint8Array());
|
||||
|
||||
testScalarStuffBuf(ScalarStuff.getRootAsScalarStuff(unpackBuf));
|
||||
|
||||
console.log('FlatBuffers --ts-undefined-for-optionals test: completed successfully');
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -99,6 +99,20 @@ flatc(
|
||||
schema="../non_zero_enum.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
options=[
|
||||
"--ts",
|
||||
"--gen-object-api",
|
||||
"--ts-undefined-for-optionals",
|
||||
],
|
||||
schema="../optional_scalars.fbs",
|
||||
prefix="ts-undefined-for-optionals",
|
||||
)
|
||||
esbuild(
|
||||
"ts-undefined-for-optionals/optional_scalars.ts",
|
||||
"ts-undefined-for-optionals/optional_scalars_generated.cjs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
options=[
|
||||
"--ts",
|
||||
@@ -201,6 +215,7 @@ check_call(NODE_CMD + ["JavaScriptUnionVectorTest"])
|
||||
check_call(NODE_CMD + ["JavaScriptFlexBuffersTest"])
|
||||
check_call(NODE_CMD + ["JavaScriptComplexArraysTest"])
|
||||
check_call(NODE_CMD + ["JavaScriptUnionUnderlyingTypeTest"])
|
||||
check_call(NODE_CMD + ["JavaScriptUndefinedForOptionals"])
|
||||
|
||||
print("Running old v1 TypeScript Tests...")
|
||||
check_call(NODE_CMD + ["JavaScriptTestv1.cjs", "./monster_test_generated.cjs"])
|
||||
|
||||
6
tests/ts/ts-undefined-for-optionals/optional-scalars.ts
Normal file
6
tests/ts/ts-undefined-for-optionals/optional-scalars.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
export { OptionalByte } from './optional-scalars/optional-byte.js';
|
||||
export { ScalarStuff, ScalarStuffT } from './optional-scalars/scalar-stuff.js';
|
||||
@@ -0,0 +1,9 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
export enum OptionalByte {
|
||||
None = 0,
|
||||
One = 1,
|
||||
Two = 2
|
||||
}
|
||||
@@ -0,0 +1,589 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { OptionalByte } from '../optional-scalars/optional-byte.js';
|
||||
|
||||
|
||||
export class ScalarStuff implements flatbuffers.IUnpackableObject<ScalarStuffT> {
|
||||
bb: flatbuffers.ByteBuffer|undefined = undefined;
|
||||
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|undefined {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.readInt8(this.bb_pos + offset) : undefined;
|
||||
}
|
||||
|
||||
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|undefined {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb!.readUint8(this.bb_pos + offset) : undefined;
|
||||
}
|
||||
|
||||
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|undefined {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 18);
|
||||
return offset ? this.bb!.readInt16(this.bb_pos + offset) : undefined;
|
||||
}
|
||||
|
||||
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|undefined {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 24);
|
||||
return offset ? this.bb!.readUint16(this.bb_pos + offset) : undefined;
|
||||
}
|
||||
|
||||
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|undefined {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 30);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : undefined;
|
||||
}
|
||||
|
||||
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|undefined {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 36);
|
||||
return offset ? this.bb!.readUint32(this.bb_pos + offset) : undefined;
|
||||
}
|
||||
|
||||
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|undefined {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 42);
|
||||
return offset ? this.bb!.readInt64(this.bb_pos + offset) : undefined;
|
||||
}
|
||||
|
||||
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|undefined {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 48);
|
||||
return offset ? this.bb!.readUint64(this.bb_pos + offset) : undefined;
|
||||
}
|
||||
|
||||
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|undefined {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 54);
|
||||
return offset ? this.bb!.readFloat32(this.bb_pos + offset) : undefined;
|
||||
}
|
||||
|
||||
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|undefined {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 60);
|
||||
return offset ? this.bb!.readFloat64(this.bb_pos + offset) : undefined;
|
||||
}
|
||||
|
||||
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|undefined {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 66);
|
||||
return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : undefined;
|
||||
}
|
||||
|
||||
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|undefined {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 72);
|
||||
return offset ? this.bb!.readInt8(this.bb_pos + offset) : undefined;
|
||||
}
|
||||
|
||||
defaultEnum():OptionalByte {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 74);
|
||||
return offset ? this.bb!.readInt8(this.bb_pos + offset) : OptionalByte.One;
|
||||
}
|
||||
|
||||
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, undefined);
|
||||
}
|
||||
|
||||
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, undefined);
|
||||
}
|
||||
|
||||
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, undefined);
|
||||
}
|
||||
|
||||
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, undefined);
|
||||
}
|
||||
|
||||
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, undefined);
|
||||
}
|
||||
|
||||
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, undefined);
|
||||
}
|
||||
|
||||
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, undefined);
|
||||
}
|
||||
|
||||
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, undefined);
|
||||
}
|
||||
|
||||
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, undefined);
|
||||
}
|
||||
|
||||
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, undefined);
|
||||
}
|
||||
|
||||
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, undefined);
|
||||
}
|
||||
|
||||
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, undefined);
|
||||
}
|
||||
|
||||
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|undefined, defaultI8:number, justU8:number, maybeU8:number|undefined, defaultU8:number, justI16:number, maybeI16:number|undefined, defaultI16:number, justU16:number, maybeU16:number|undefined, defaultU16:number, justI32:number, maybeI32:number|undefined, defaultI32:number, justU32:number, maybeU32:number|undefined, defaultU32:number, justI64:bigint, maybeI64:bigint|undefined, defaultI64:bigint, justU64:bigint, maybeU64:bigint|undefined, defaultU64:bigint, justF32:number, maybeF32:number|undefined, defaultF32:number, justF64:number, maybeF64:number|undefined, defaultF64:number, justBool:boolean, maybeBool:boolean|undefined, defaultBool:boolean, justEnum:OptionalByte, maybeEnum:OptionalByte|undefined, defaultEnum:OptionalByte):flatbuffers.Offset {
|
||||
ScalarStuff.startScalarStuff(builder);
|
||||
ScalarStuff.addJustI8(builder, justI8);
|
||||
if (maybeI8 !== undefined)
|
||||
ScalarStuff.addMaybeI8(builder, maybeI8);
|
||||
ScalarStuff.addDefaultI8(builder, defaultI8);
|
||||
ScalarStuff.addJustU8(builder, justU8);
|
||||
if (maybeU8 !== undefined)
|
||||
ScalarStuff.addMaybeU8(builder, maybeU8);
|
||||
ScalarStuff.addDefaultU8(builder, defaultU8);
|
||||
ScalarStuff.addJustI16(builder, justI16);
|
||||
if (maybeI16 !== undefined)
|
||||
ScalarStuff.addMaybeI16(builder, maybeI16);
|
||||
ScalarStuff.addDefaultI16(builder, defaultI16);
|
||||
ScalarStuff.addJustU16(builder, justU16);
|
||||
if (maybeU16 !== undefined)
|
||||
ScalarStuff.addMaybeU16(builder, maybeU16);
|
||||
ScalarStuff.addDefaultU16(builder, defaultU16);
|
||||
ScalarStuff.addJustI32(builder, justI32);
|
||||
if (maybeI32 !== undefined)
|
||||
ScalarStuff.addMaybeI32(builder, maybeI32);
|
||||
ScalarStuff.addDefaultI32(builder, defaultI32);
|
||||
ScalarStuff.addJustU32(builder, justU32);
|
||||
if (maybeU32 !== undefined)
|
||||
ScalarStuff.addMaybeU32(builder, maybeU32);
|
||||
ScalarStuff.addDefaultU32(builder, defaultU32);
|
||||
ScalarStuff.addJustI64(builder, justI64);
|
||||
if (maybeI64 !== undefined)
|
||||
ScalarStuff.addMaybeI64(builder, maybeI64);
|
||||
ScalarStuff.addDefaultI64(builder, defaultI64);
|
||||
ScalarStuff.addJustU64(builder, justU64);
|
||||
if (maybeU64 !== undefined)
|
||||
ScalarStuff.addMaybeU64(builder, maybeU64);
|
||||
ScalarStuff.addDefaultU64(builder, defaultU64);
|
||||
ScalarStuff.addJustF32(builder, justF32);
|
||||
if (maybeF32 !== undefined)
|
||||
ScalarStuff.addMaybeF32(builder, maybeF32);
|
||||
ScalarStuff.addDefaultF32(builder, defaultF32);
|
||||
ScalarStuff.addJustF64(builder, justF64);
|
||||
if (maybeF64 !== undefined)
|
||||
ScalarStuff.addMaybeF64(builder, maybeF64);
|
||||
ScalarStuff.addDefaultF64(builder, defaultF64);
|
||||
ScalarStuff.addJustBool(builder, justBool);
|
||||
if (maybeBool !== undefined)
|
||||
ScalarStuff.addMaybeBool(builder, maybeBool);
|
||||
ScalarStuff.addDefaultBool(builder, defaultBool);
|
||||
ScalarStuff.addJustEnum(builder, justEnum);
|
||||
if (maybeEnum !== undefined)
|
||||
ScalarStuff.addMaybeEnum(builder, maybeEnum);
|
||||
ScalarStuff.addDefaultEnum(builder, defaultEnum);
|
||||
return ScalarStuff.endScalarStuff(builder);
|
||||
}
|
||||
|
||||
unpack(): ScalarStuffT {
|
||||
return new ScalarStuffT(
|
||||
this.justI8(),
|
||||
this.maybeI8(),
|
||||
this.defaultI8(),
|
||||
this.justU8(),
|
||||
this.maybeU8(),
|
||||
this.defaultU8(),
|
||||
this.justI16(),
|
||||
this.maybeI16(),
|
||||
this.defaultI16(),
|
||||
this.justU16(),
|
||||
this.maybeU16(),
|
||||
this.defaultU16(),
|
||||
this.justI32(),
|
||||
this.maybeI32(),
|
||||
this.defaultI32(),
|
||||
this.justU32(),
|
||||
this.maybeU32(),
|
||||
this.defaultU32(),
|
||||
this.justI64(),
|
||||
this.maybeI64(),
|
||||
this.defaultI64(),
|
||||
this.justU64(),
|
||||
this.maybeU64(),
|
||||
this.defaultU64(),
|
||||
this.justF32(),
|
||||
this.maybeF32(),
|
||||
this.defaultF32(),
|
||||
this.justF64(),
|
||||
this.maybeF64(),
|
||||
this.defaultF64(),
|
||||
this.justBool(),
|
||||
this.maybeBool(),
|
||||
this.defaultBool(),
|
||||
this.justEnum(),
|
||||
this.maybeEnum(),
|
||||
this.defaultEnum()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: ScalarStuffT): void {
|
||||
_o.justI8 = this.justI8();
|
||||
_o.maybeI8 = this.maybeI8();
|
||||
_o.defaultI8 = this.defaultI8();
|
||||
_o.justU8 = this.justU8();
|
||||
_o.maybeU8 = this.maybeU8();
|
||||
_o.defaultU8 = this.defaultU8();
|
||||
_o.justI16 = this.justI16();
|
||||
_o.maybeI16 = this.maybeI16();
|
||||
_o.defaultI16 = this.defaultI16();
|
||||
_o.justU16 = this.justU16();
|
||||
_o.maybeU16 = this.maybeU16();
|
||||
_o.defaultU16 = this.defaultU16();
|
||||
_o.justI32 = this.justI32();
|
||||
_o.maybeI32 = this.maybeI32();
|
||||
_o.defaultI32 = this.defaultI32();
|
||||
_o.justU32 = this.justU32();
|
||||
_o.maybeU32 = this.maybeU32();
|
||||
_o.defaultU32 = this.defaultU32();
|
||||
_o.justI64 = this.justI64();
|
||||
_o.maybeI64 = this.maybeI64();
|
||||
_o.defaultI64 = this.defaultI64();
|
||||
_o.justU64 = this.justU64();
|
||||
_o.maybeU64 = this.maybeU64();
|
||||
_o.defaultU64 = this.defaultU64();
|
||||
_o.justF32 = this.justF32();
|
||||
_o.maybeF32 = this.maybeF32();
|
||||
_o.defaultF32 = this.defaultF32();
|
||||
_o.justF64 = this.justF64();
|
||||
_o.maybeF64 = this.maybeF64();
|
||||
_o.defaultF64 = this.defaultF64();
|
||||
_o.justBool = this.justBool();
|
||||
_o.maybeBool = this.maybeBool();
|
||||
_o.defaultBool = this.defaultBool();
|
||||
_o.justEnum = this.justEnum();
|
||||
_o.maybeEnum = this.maybeEnum();
|
||||
_o.defaultEnum = this.defaultEnum();
|
||||
}
|
||||
}
|
||||
|
||||
export class ScalarStuffT implements flatbuffers.IGeneratedObject {
|
||||
constructor(
|
||||
public justI8: number = 0,
|
||||
public maybeI8: number|undefined = undefined,
|
||||
public defaultI8: number = 42,
|
||||
public justU8: number = 0,
|
||||
public maybeU8: number|undefined = undefined,
|
||||
public defaultU8: number = 42,
|
||||
public justI16: number = 0,
|
||||
public maybeI16: number|undefined = undefined,
|
||||
public defaultI16: number = 42,
|
||||
public justU16: number = 0,
|
||||
public maybeU16: number|undefined = undefined,
|
||||
public defaultU16: number = 42,
|
||||
public justI32: number = 0,
|
||||
public maybeI32: number|undefined = undefined,
|
||||
public defaultI32: number = 42,
|
||||
public justU32: number = 0,
|
||||
public maybeU32: number|undefined = undefined,
|
||||
public defaultU32: number = 42,
|
||||
public justI64: bigint = BigInt('0'),
|
||||
public maybeI64: bigint|undefined = undefined,
|
||||
public defaultI64: bigint = BigInt('42'),
|
||||
public justU64: bigint = BigInt('0'),
|
||||
public maybeU64: bigint|undefined = undefined,
|
||||
public defaultU64: bigint = BigInt('42'),
|
||||
public justF32: number = 0.0,
|
||||
public maybeF32: number|undefined = undefined,
|
||||
public defaultF32: number = 42.0,
|
||||
public justF64: number = 0.0,
|
||||
public maybeF64: number|undefined = undefined,
|
||||
public defaultF64: number = 42.0,
|
||||
public justBool: boolean = false,
|
||||
public maybeBool: boolean|undefined = undefined,
|
||||
public defaultBool: boolean = true,
|
||||
public justEnum: OptionalByte = OptionalByte.None,
|
||||
public maybeEnum: OptionalByte|undefined = undefined,
|
||||
public defaultEnum: OptionalByte = OptionalByte.One
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return ScalarStuff.createScalarStuff(builder,
|
||||
this.justI8,
|
||||
this.maybeI8,
|
||||
this.defaultI8,
|
||||
this.justU8,
|
||||
this.maybeU8,
|
||||
this.defaultU8,
|
||||
this.justI16,
|
||||
this.maybeI16,
|
||||
this.defaultI16,
|
||||
this.justU16,
|
||||
this.maybeU16,
|
||||
this.defaultU16,
|
||||
this.justI32,
|
||||
this.maybeI32,
|
||||
this.defaultI32,
|
||||
this.justU32,
|
||||
this.maybeU32,
|
||||
this.defaultU32,
|
||||
this.justI64,
|
||||
this.maybeI64,
|
||||
this.defaultI64,
|
||||
this.justU64,
|
||||
this.maybeU64,
|
||||
this.defaultU64,
|
||||
this.justF32,
|
||||
this.maybeF32,
|
||||
this.defaultF32,
|
||||
this.justF64,
|
||||
this.maybeF64,
|
||||
this.defaultF64,
|
||||
this.justBool,
|
||||
this.maybeBool,
|
||||
this.defaultBool,
|
||||
this.justEnum,
|
||||
this.maybeEnum,
|
||||
this.defaultEnum
|
||||
);
|
||||
}
|
||||
}
|
||||
5
tests/ts/ts-undefined-for-optionals/optional_scalars.ts
Normal file
5
tests/ts/ts-undefined-for-optionals/optional_scalars.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
export * as optional_scalars from './optional-scalars.js';
|
||||
@@ -0,0 +1,551 @@
|
||||
"use strict";
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// ts-undefined-for-optionals/optional_scalars.ts
|
||||
var optional_scalars_exports2 = {};
|
||||
__export(optional_scalars_exports2, {
|
||||
optional_scalars: () => optional_scalars_exports
|
||||
});
|
||||
module.exports = __toCommonJS(optional_scalars_exports2);
|
||||
|
||||
// ts-undefined-for-optionals/optional-scalars.ts
|
||||
var optional_scalars_exports = {};
|
||||
__export(optional_scalars_exports, {
|
||||
OptionalByte: () => OptionalByte,
|
||||
ScalarStuff: () => ScalarStuff,
|
||||
ScalarStuffT: () => ScalarStuffT
|
||||
});
|
||||
|
||||
// ts-undefined-for-optionals/optional-scalars/optional-byte.ts
|
||||
var OptionalByte = /* @__PURE__ */ ((OptionalByte2) => {
|
||||
OptionalByte2[OptionalByte2["None"] = 0] = "None";
|
||||
OptionalByte2[OptionalByte2["One"] = 1] = "One";
|
||||
OptionalByte2[OptionalByte2["Two"] = 2] = "Two";
|
||||
return OptionalByte2;
|
||||
})(OptionalByte || {});
|
||||
|
||||
// ts-undefined-for-optionals/optional-scalars/scalar-stuff.ts
|
||||
var flatbuffers = __toESM(require("flatbuffers"), 1);
|
||||
var ScalarStuff = class _ScalarStuff {
|
||||
constructor() {
|
||||
this.bb = void 0;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsScalarStuff(bb, obj) {
|
||||
return (obj || new _ScalarStuff()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsScalarStuff(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new _ScalarStuff()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static bufferHasIdentifier(bb) {
|
||||
return bb.__has_identifier("NULL");
|
||||
}
|
||||
justI8() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.readInt8(this.bb_pos + offset) : 0;
|
||||
}
|
||||
maybeI8() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb.readInt8(this.bb_pos + offset) : void 0;
|
||||
}
|
||||
defaultI8() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb.readInt8(this.bb_pos + offset) : 42;
|
||||
}
|
||||
justU8() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb.readUint8(this.bb_pos + offset) : 0;
|
||||
}
|
||||
maybeU8() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb.readUint8(this.bb_pos + offset) : void 0;
|
||||
}
|
||||
defaultU8() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb.readUint8(this.bb_pos + offset) : 42;
|
||||
}
|
||||
justI16() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 16);
|
||||
return offset ? this.bb.readInt16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
maybeI16() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 18);
|
||||
return offset ? this.bb.readInt16(this.bb_pos + offset) : void 0;
|
||||
}
|
||||
defaultI16() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 20);
|
||||
return offset ? this.bb.readInt16(this.bb_pos + offset) : 42;
|
||||
}
|
||||
justU16() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 22);
|
||||
return offset ? this.bb.readUint16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
maybeU16() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 24);
|
||||
return offset ? this.bb.readUint16(this.bb_pos + offset) : void 0;
|
||||
}
|
||||
defaultU16() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 26);
|
||||
return offset ? this.bb.readUint16(this.bb_pos + offset) : 42;
|
||||
}
|
||||
justI32() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 28);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
maybeI32() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 30);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : void 0;
|
||||
}
|
||||
defaultI32() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 32);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : 42;
|
||||
}
|
||||
justU32() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 34);
|
||||
return offset ? this.bb.readUint32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
maybeU32() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 36);
|
||||
return offset ? this.bb.readUint32(this.bb_pos + offset) : void 0;
|
||||
}
|
||||
defaultU32() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 38);
|
||||
return offset ? this.bb.readUint32(this.bb_pos + offset) : 42;
|
||||
}
|
||||
justI64() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 40);
|
||||
return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt("0");
|
||||
}
|
||||
maybeI64() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 42);
|
||||
return offset ? this.bb.readInt64(this.bb_pos + offset) : void 0;
|
||||
}
|
||||
defaultI64() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 44);
|
||||
return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt("42");
|
||||
}
|
||||
justU64() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 46);
|
||||
return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt("0");
|
||||
}
|
||||
maybeU64() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 48);
|
||||
return offset ? this.bb.readUint64(this.bb_pos + offset) : void 0;
|
||||
}
|
||||
defaultU64() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 50);
|
||||
return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt("42");
|
||||
}
|
||||
justF32() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 52);
|
||||
return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
maybeF32() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 54);
|
||||
return offset ? this.bb.readFloat32(this.bb_pos + offset) : void 0;
|
||||
}
|
||||
defaultF32() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 56);
|
||||
return offset ? this.bb.readFloat32(this.bb_pos + offset) : 42;
|
||||
}
|
||||
justF64() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 58);
|
||||
return offset ? this.bb.readFloat64(this.bb_pos + offset) : 0;
|
||||
}
|
||||
maybeF64() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 60);
|
||||
return offset ? this.bb.readFloat64(this.bb_pos + offset) : void 0;
|
||||
}
|
||||
defaultF64() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 62);
|
||||
return offset ? this.bb.readFloat64(this.bb_pos + offset) : 42;
|
||||
}
|
||||
justBool() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 64);
|
||||
return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false;
|
||||
}
|
||||
maybeBool() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 66);
|
||||
return offset ? !!this.bb.readInt8(this.bb_pos + offset) : void 0;
|
||||
}
|
||||
defaultBool() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 68);
|
||||
return offset ? !!this.bb.readInt8(this.bb_pos + offset) : true;
|
||||
}
|
||||
justEnum() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 70);
|
||||
return offset ? this.bb.readInt8(this.bb_pos + offset) : 0 /* None */;
|
||||
}
|
||||
maybeEnum() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 72);
|
||||
return offset ? this.bb.readInt8(this.bb_pos + offset) : void 0;
|
||||
}
|
||||
defaultEnum() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 74);
|
||||
return offset ? this.bb.readInt8(this.bb_pos + offset) : 1 /* One */;
|
||||
}
|
||||
static startScalarStuff(builder) {
|
||||
builder.startObject(36);
|
||||
}
|
||||
static addJustI8(builder, justI8) {
|
||||
builder.addFieldInt8(0, justI8, 0);
|
||||
}
|
||||
static addMaybeI8(builder, maybeI8) {
|
||||
builder.addFieldInt8(1, maybeI8, void 0);
|
||||
}
|
||||
static addDefaultI8(builder, defaultI8) {
|
||||
builder.addFieldInt8(2, defaultI8, 42);
|
||||
}
|
||||
static addJustU8(builder, justU8) {
|
||||
builder.addFieldInt8(3, justU8, 0);
|
||||
}
|
||||
static addMaybeU8(builder, maybeU8) {
|
||||
builder.addFieldInt8(4, maybeU8, void 0);
|
||||
}
|
||||
static addDefaultU8(builder, defaultU8) {
|
||||
builder.addFieldInt8(5, defaultU8, 42);
|
||||
}
|
||||
static addJustI16(builder, justI16) {
|
||||
builder.addFieldInt16(6, justI16, 0);
|
||||
}
|
||||
static addMaybeI16(builder, maybeI16) {
|
||||
builder.addFieldInt16(7, maybeI16, void 0);
|
||||
}
|
||||
static addDefaultI16(builder, defaultI16) {
|
||||
builder.addFieldInt16(8, defaultI16, 42);
|
||||
}
|
||||
static addJustU16(builder, justU16) {
|
||||
builder.addFieldInt16(9, justU16, 0);
|
||||
}
|
||||
static addMaybeU16(builder, maybeU16) {
|
||||
builder.addFieldInt16(10, maybeU16, void 0);
|
||||
}
|
||||
static addDefaultU16(builder, defaultU16) {
|
||||
builder.addFieldInt16(11, defaultU16, 42);
|
||||
}
|
||||
static addJustI32(builder, justI32) {
|
||||
builder.addFieldInt32(12, justI32, 0);
|
||||
}
|
||||
static addMaybeI32(builder, maybeI32) {
|
||||
builder.addFieldInt32(13, maybeI32, void 0);
|
||||
}
|
||||
static addDefaultI32(builder, defaultI32) {
|
||||
builder.addFieldInt32(14, defaultI32, 42);
|
||||
}
|
||||
static addJustU32(builder, justU32) {
|
||||
builder.addFieldInt32(15, justU32, 0);
|
||||
}
|
||||
static addMaybeU32(builder, maybeU32) {
|
||||
builder.addFieldInt32(16, maybeU32, void 0);
|
||||
}
|
||||
static addDefaultU32(builder, defaultU32) {
|
||||
builder.addFieldInt32(17, defaultU32, 42);
|
||||
}
|
||||
static addJustI64(builder, justI64) {
|
||||
builder.addFieldInt64(18, justI64, BigInt("0"));
|
||||
}
|
||||
static addMaybeI64(builder, maybeI64) {
|
||||
builder.addFieldInt64(19, maybeI64, void 0);
|
||||
}
|
||||
static addDefaultI64(builder, defaultI64) {
|
||||
builder.addFieldInt64(20, defaultI64, BigInt("42"));
|
||||
}
|
||||
static addJustU64(builder, justU64) {
|
||||
builder.addFieldInt64(21, justU64, BigInt("0"));
|
||||
}
|
||||
static addMaybeU64(builder, maybeU64) {
|
||||
builder.addFieldInt64(22, maybeU64, void 0);
|
||||
}
|
||||
static addDefaultU64(builder, defaultU64) {
|
||||
builder.addFieldInt64(23, defaultU64, BigInt("42"));
|
||||
}
|
||||
static addJustF32(builder, justF32) {
|
||||
builder.addFieldFloat32(24, justF32, 0);
|
||||
}
|
||||
static addMaybeF32(builder, maybeF32) {
|
||||
builder.addFieldFloat32(25, maybeF32, void 0);
|
||||
}
|
||||
static addDefaultF32(builder, defaultF32) {
|
||||
builder.addFieldFloat32(26, defaultF32, 42);
|
||||
}
|
||||
static addJustF64(builder, justF64) {
|
||||
builder.addFieldFloat64(27, justF64, 0);
|
||||
}
|
||||
static addMaybeF64(builder, maybeF64) {
|
||||
builder.addFieldFloat64(28, maybeF64, void 0);
|
||||
}
|
||||
static addDefaultF64(builder, defaultF64) {
|
||||
builder.addFieldFloat64(29, defaultF64, 42);
|
||||
}
|
||||
static addJustBool(builder, justBool) {
|
||||
builder.addFieldInt8(30, +justBool, 0);
|
||||
}
|
||||
static addMaybeBool(builder, maybeBool) {
|
||||
builder.addFieldInt8(31, +maybeBool, void 0);
|
||||
}
|
||||
static addDefaultBool(builder, defaultBool) {
|
||||
builder.addFieldInt8(32, +defaultBool, 1);
|
||||
}
|
||||
static addJustEnum(builder, justEnum) {
|
||||
builder.addFieldInt8(33, justEnum, 0 /* None */);
|
||||
}
|
||||
static addMaybeEnum(builder, maybeEnum) {
|
||||
builder.addFieldInt8(34, maybeEnum, void 0);
|
||||
}
|
||||
static addDefaultEnum(builder, defaultEnum) {
|
||||
builder.addFieldInt8(35, defaultEnum, 1 /* One */);
|
||||
}
|
||||
static endScalarStuff(builder) {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
static finishScalarStuffBuffer(builder, offset) {
|
||||
builder.finish(offset, "NULL");
|
||||
}
|
||||
static finishSizePrefixedScalarStuffBuffer(builder, offset) {
|
||||
builder.finish(offset, "NULL", true);
|
||||
}
|
||||
static createScalarStuff(builder, justI8, maybeI8, defaultI8, justU8, maybeU8, defaultU8, justI16, maybeI16, defaultI16, justU16, maybeU16, defaultU16, justI32, maybeI32, defaultI32, justU32, maybeU32, defaultU32, justI64, maybeI64, defaultI64, justU64, maybeU64, defaultU64, justF32, maybeF32, defaultF32, justF64, maybeF64, defaultF64, justBool, maybeBool, defaultBool, justEnum, maybeEnum, defaultEnum) {
|
||||
_ScalarStuff.startScalarStuff(builder);
|
||||
_ScalarStuff.addJustI8(builder, justI8);
|
||||
if (maybeI8 !== void 0)
|
||||
_ScalarStuff.addMaybeI8(builder, maybeI8);
|
||||
_ScalarStuff.addDefaultI8(builder, defaultI8);
|
||||
_ScalarStuff.addJustU8(builder, justU8);
|
||||
if (maybeU8 !== void 0)
|
||||
_ScalarStuff.addMaybeU8(builder, maybeU8);
|
||||
_ScalarStuff.addDefaultU8(builder, defaultU8);
|
||||
_ScalarStuff.addJustI16(builder, justI16);
|
||||
if (maybeI16 !== void 0)
|
||||
_ScalarStuff.addMaybeI16(builder, maybeI16);
|
||||
_ScalarStuff.addDefaultI16(builder, defaultI16);
|
||||
_ScalarStuff.addJustU16(builder, justU16);
|
||||
if (maybeU16 !== void 0)
|
||||
_ScalarStuff.addMaybeU16(builder, maybeU16);
|
||||
_ScalarStuff.addDefaultU16(builder, defaultU16);
|
||||
_ScalarStuff.addJustI32(builder, justI32);
|
||||
if (maybeI32 !== void 0)
|
||||
_ScalarStuff.addMaybeI32(builder, maybeI32);
|
||||
_ScalarStuff.addDefaultI32(builder, defaultI32);
|
||||
_ScalarStuff.addJustU32(builder, justU32);
|
||||
if (maybeU32 !== void 0)
|
||||
_ScalarStuff.addMaybeU32(builder, maybeU32);
|
||||
_ScalarStuff.addDefaultU32(builder, defaultU32);
|
||||
_ScalarStuff.addJustI64(builder, justI64);
|
||||
if (maybeI64 !== void 0)
|
||||
_ScalarStuff.addMaybeI64(builder, maybeI64);
|
||||
_ScalarStuff.addDefaultI64(builder, defaultI64);
|
||||
_ScalarStuff.addJustU64(builder, justU64);
|
||||
if (maybeU64 !== void 0)
|
||||
_ScalarStuff.addMaybeU64(builder, maybeU64);
|
||||
_ScalarStuff.addDefaultU64(builder, defaultU64);
|
||||
_ScalarStuff.addJustF32(builder, justF32);
|
||||
if (maybeF32 !== void 0)
|
||||
_ScalarStuff.addMaybeF32(builder, maybeF32);
|
||||
_ScalarStuff.addDefaultF32(builder, defaultF32);
|
||||
_ScalarStuff.addJustF64(builder, justF64);
|
||||
if (maybeF64 !== void 0)
|
||||
_ScalarStuff.addMaybeF64(builder, maybeF64);
|
||||
_ScalarStuff.addDefaultF64(builder, defaultF64);
|
||||
_ScalarStuff.addJustBool(builder, justBool);
|
||||
if (maybeBool !== void 0)
|
||||
_ScalarStuff.addMaybeBool(builder, maybeBool);
|
||||
_ScalarStuff.addDefaultBool(builder, defaultBool);
|
||||
_ScalarStuff.addJustEnum(builder, justEnum);
|
||||
if (maybeEnum !== void 0)
|
||||
_ScalarStuff.addMaybeEnum(builder, maybeEnum);
|
||||
_ScalarStuff.addDefaultEnum(builder, defaultEnum);
|
||||
return _ScalarStuff.endScalarStuff(builder);
|
||||
}
|
||||
unpack() {
|
||||
return new ScalarStuffT(
|
||||
this.justI8(),
|
||||
this.maybeI8(),
|
||||
this.defaultI8(),
|
||||
this.justU8(),
|
||||
this.maybeU8(),
|
||||
this.defaultU8(),
|
||||
this.justI16(),
|
||||
this.maybeI16(),
|
||||
this.defaultI16(),
|
||||
this.justU16(),
|
||||
this.maybeU16(),
|
||||
this.defaultU16(),
|
||||
this.justI32(),
|
||||
this.maybeI32(),
|
||||
this.defaultI32(),
|
||||
this.justU32(),
|
||||
this.maybeU32(),
|
||||
this.defaultU32(),
|
||||
this.justI64(),
|
||||
this.maybeI64(),
|
||||
this.defaultI64(),
|
||||
this.justU64(),
|
||||
this.maybeU64(),
|
||||
this.defaultU64(),
|
||||
this.justF32(),
|
||||
this.maybeF32(),
|
||||
this.defaultF32(),
|
||||
this.justF64(),
|
||||
this.maybeF64(),
|
||||
this.defaultF64(),
|
||||
this.justBool(),
|
||||
this.maybeBool(),
|
||||
this.defaultBool(),
|
||||
this.justEnum(),
|
||||
this.maybeEnum(),
|
||||
this.defaultEnum()
|
||||
);
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.justI8 = this.justI8();
|
||||
_o.maybeI8 = this.maybeI8();
|
||||
_o.defaultI8 = this.defaultI8();
|
||||
_o.justU8 = this.justU8();
|
||||
_o.maybeU8 = this.maybeU8();
|
||||
_o.defaultU8 = this.defaultU8();
|
||||
_o.justI16 = this.justI16();
|
||||
_o.maybeI16 = this.maybeI16();
|
||||
_o.defaultI16 = this.defaultI16();
|
||||
_o.justU16 = this.justU16();
|
||||
_o.maybeU16 = this.maybeU16();
|
||||
_o.defaultU16 = this.defaultU16();
|
||||
_o.justI32 = this.justI32();
|
||||
_o.maybeI32 = this.maybeI32();
|
||||
_o.defaultI32 = this.defaultI32();
|
||||
_o.justU32 = this.justU32();
|
||||
_o.maybeU32 = this.maybeU32();
|
||||
_o.defaultU32 = this.defaultU32();
|
||||
_o.justI64 = this.justI64();
|
||||
_o.maybeI64 = this.maybeI64();
|
||||
_o.defaultI64 = this.defaultI64();
|
||||
_o.justU64 = this.justU64();
|
||||
_o.maybeU64 = this.maybeU64();
|
||||
_o.defaultU64 = this.defaultU64();
|
||||
_o.justF32 = this.justF32();
|
||||
_o.maybeF32 = this.maybeF32();
|
||||
_o.defaultF32 = this.defaultF32();
|
||||
_o.justF64 = this.justF64();
|
||||
_o.maybeF64 = this.maybeF64();
|
||||
_o.defaultF64 = this.defaultF64();
|
||||
_o.justBool = this.justBool();
|
||||
_o.maybeBool = this.maybeBool();
|
||||
_o.defaultBool = this.defaultBool();
|
||||
_o.justEnum = this.justEnum();
|
||||
_o.maybeEnum = this.maybeEnum();
|
||||
_o.defaultEnum = this.defaultEnum();
|
||||
}
|
||||
};
|
||||
var ScalarStuffT = class {
|
||||
constructor(justI8 = 0, maybeI8 = void 0, defaultI8 = 42, justU8 = 0, maybeU8 = void 0, defaultU8 = 42, justI16 = 0, maybeI16 = void 0, defaultI16 = 42, justU16 = 0, maybeU16 = void 0, defaultU16 = 42, justI32 = 0, maybeI32 = void 0, defaultI32 = 42, justU32 = 0, maybeU32 = void 0, defaultU32 = 42, justI64 = BigInt("0"), maybeI64 = void 0, defaultI64 = BigInt("42"), justU64 = BigInt("0"), maybeU64 = void 0, defaultU64 = BigInt("42"), justF32 = 0, maybeF32 = void 0, defaultF32 = 42, justF64 = 0, maybeF64 = void 0, defaultF64 = 42, justBool = false, maybeBool = void 0, defaultBool = true, justEnum = 0 /* None */, maybeEnum = void 0, defaultEnum = 1 /* One */) {
|
||||
this.justI8 = justI8;
|
||||
this.maybeI8 = maybeI8;
|
||||
this.defaultI8 = defaultI8;
|
||||
this.justU8 = justU8;
|
||||
this.maybeU8 = maybeU8;
|
||||
this.defaultU8 = defaultU8;
|
||||
this.justI16 = justI16;
|
||||
this.maybeI16 = maybeI16;
|
||||
this.defaultI16 = defaultI16;
|
||||
this.justU16 = justU16;
|
||||
this.maybeU16 = maybeU16;
|
||||
this.defaultU16 = defaultU16;
|
||||
this.justI32 = justI32;
|
||||
this.maybeI32 = maybeI32;
|
||||
this.defaultI32 = defaultI32;
|
||||
this.justU32 = justU32;
|
||||
this.maybeU32 = maybeU32;
|
||||
this.defaultU32 = defaultU32;
|
||||
this.justI64 = justI64;
|
||||
this.maybeI64 = maybeI64;
|
||||
this.defaultI64 = defaultI64;
|
||||
this.justU64 = justU64;
|
||||
this.maybeU64 = maybeU64;
|
||||
this.defaultU64 = defaultU64;
|
||||
this.justF32 = justF32;
|
||||
this.maybeF32 = maybeF32;
|
||||
this.defaultF32 = defaultF32;
|
||||
this.justF64 = justF64;
|
||||
this.maybeF64 = maybeF64;
|
||||
this.defaultF64 = defaultF64;
|
||||
this.justBool = justBool;
|
||||
this.maybeBool = maybeBool;
|
||||
this.defaultBool = defaultBool;
|
||||
this.justEnum = justEnum;
|
||||
this.maybeEnum = maybeEnum;
|
||||
this.defaultEnum = defaultEnum;
|
||||
}
|
||||
pack(builder) {
|
||||
return ScalarStuff.createScalarStuff(
|
||||
builder,
|
||||
this.justI8,
|
||||
this.maybeI8,
|
||||
this.defaultI8,
|
||||
this.justU8,
|
||||
this.maybeU8,
|
||||
this.defaultU8,
|
||||
this.justI16,
|
||||
this.maybeI16,
|
||||
this.defaultI16,
|
||||
this.justU16,
|
||||
this.maybeU16,
|
||||
this.defaultU16,
|
||||
this.justI32,
|
||||
this.maybeI32,
|
||||
this.defaultI32,
|
||||
this.justU32,
|
||||
this.maybeU32,
|
||||
this.defaultU32,
|
||||
this.justI64,
|
||||
this.maybeI64,
|
||||
this.defaultI64,
|
||||
this.justU64,
|
||||
this.maybeU64,
|
||||
this.defaultU64,
|
||||
this.justF32,
|
||||
this.maybeF32,
|
||||
this.defaultF32,
|
||||
this.justF64,
|
||||
this.maybeF64,
|
||||
this.defaultF64,
|
||||
this.justBool,
|
||||
this.maybeBool,
|
||||
this.defaultBool,
|
||||
this.justEnum,
|
||||
this.maybeEnum,
|
||||
this.defaultEnum
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -212,7 +212,7 @@ export class Builder {
|
||||
addFieldInt8(
|
||||
voffset: number,
|
||||
value: number,
|
||||
defaultValue: number | null,
|
||||
defaultValue: number | null | undefined,
|
||||
): void {
|
||||
if (this.force_defaults || value != defaultValue) {
|
||||
this.addInt8(value);
|
||||
@@ -223,7 +223,7 @@ export class Builder {
|
||||
addFieldInt16(
|
||||
voffset: number,
|
||||
value: number,
|
||||
defaultValue: number | null,
|
||||
defaultValue: number | null | undefined,
|
||||
): void {
|
||||
if (this.force_defaults || value != defaultValue) {
|
||||
this.addInt16(value);
|
||||
@@ -234,7 +234,7 @@ export class Builder {
|
||||
addFieldInt32(
|
||||
voffset: number,
|
||||
value: number,
|
||||
defaultValue: number | null,
|
||||
defaultValue: number | null | undefined,
|
||||
): void {
|
||||
if (this.force_defaults || value != defaultValue) {
|
||||
this.addInt32(value);
|
||||
@@ -245,7 +245,7 @@ export class Builder {
|
||||
addFieldInt64(
|
||||
voffset: number,
|
||||
value: bigint,
|
||||
defaultValue: bigint | null,
|
||||
defaultValue: bigint | null | undefined,
|
||||
): void {
|
||||
if (this.force_defaults || value !== defaultValue) {
|
||||
this.addInt64(value);
|
||||
@@ -256,7 +256,7 @@ export class Builder {
|
||||
addFieldFloat32(
|
||||
voffset: number,
|
||||
value: number,
|
||||
defaultValue: number | null,
|
||||
defaultValue: number | null | undefined,
|
||||
): void {
|
||||
if (this.force_defaults || value != defaultValue) {
|
||||
this.addFloat32(value);
|
||||
@@ -267,7 +267,7 @@ export class Builder {
|
||||
addFieldFloat64(
|
||||
voffset: number,
|
||||
value: number,
|
||||
defaultValue: number | null,
|
||||
defaultValue: number | null | undefined,
|
||||
): void {
|
||||
if (this.force_defaults || value != defaultValue) {
|
||||
this.addFloat64(value);
|
||||
@@ -614,8 +614,8 @@ export class Builder {
|
||||
*
|
||||
* @returns offset of obj
|
||||
*/
|
||||
createObjectOffset(obj: string | IGeneratedObject | null): Offset {
|
||||
if (obj === null) {
|
||||
createObjectOffset(obj: string | IGeneratedObject | null | undefined): Offset {
|
||||
if (obj === null || obj === undefined) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -629,7 +629,7 @@ export class Builder {
|
||||
/**
|
||||
* A helper function to pack a list of object
|
||||
*
|
||||
* @returns list of offsets of each non null object
|
||||
* @returns list of offsets of each non null/undefined object
|
||||
*/
|
||||
createObjectOffsetList(list: (string | IGeneratedObject)[]): Offset[] {
|
||||
const ret: number[] = [];
|
||||
@@ -637,11 +637,11 @@ export class Builder {
|
||||
for (let i = 0; i < list.length; ++i) {
|
||||
const val = list[i];
|
||||
|
||||
if (val !== null) {
|
||||
if (val !== null && val !== undefined) {
|
||||
ret.push(this.createObjectOffset(val));
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'FlatBuffers: Argument for createObjectOffsetList cannot contain null.',
|
||||
'FlatBuffers: Argument for createObjectOffsetList cannot contain null or undefined.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-namespace */
|
||||
import {Builder} from './flexbuffers/builder.js';
|
||||
import {toReference} from './flexbuffers/reference.js';
|
||||
export {toReference} from './flexbuffers/reference.js';
|
||||
|
||||
Reference in New Issue
Block a user