mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-18 08:54:26 +00:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
203241ed32 | ||
|
|
ac485609c4 | ||
|
|
de5b85aa66 | ||
|
|
de3df2d88b | ||
|
|
043a24f2e4 | ||
|
|
5a48b0d7d6 | ||
|
|
ce307556fb | ||
|
|
cb616e27cb | ||
|
|
a54ca1e759 | ||
|
|
5b3fadcc16 | ||
|
|
872a497464 | ||
|
|
e301702964 | ||
|
|
f7b734438d | ||
|
|
5792623df4 | ||
|
|
0edb275285 | ||
|
|
acc6a20d39 | ||
|
|
04cd037ba2 | ||
|
|
e1c5db988a | ||
|
|
b80142b901 | ||
|
|
54418f371b |
6
.github/labeler.yml
vendored
6
.github/labeler.yml
vendored
@@ -18,6 +18,12 @@ swift:
|
|||||||
- tests/swift/**
|
- tests/swift/**
|
||||||
- src/idl_gen_swift.cpp
|
- src/idl_gen_swift.cpp
|
||||||
|
|
||||||
|
nim:
|
||||||
|
- '**/*.nim'
|
||||||
|
- nim/**/*
|
||||||
|
- src/idl_gen_nim.cpp
|
||||||
|
- src/bfbs_gen_nim.cpp
|
||||||
|
|
||||||
javascript:
|
javascript:
|
||||||
- '**/*.js'
|
- '**/*.js'
|
||||||
- src/idl_gen_ts.cpp
|
- src/idl_gen_ts.cpp
|
||||||
|
|||||||
16
.github/workflows/build.yml
vendored
16
.github/workflows/build.yml
vendored
@@ -477,6 +477,22 @@ jobs:
|
|||||||
working-directory: tests
|
working-directory: tests
|
||||||
run: bash DartTest.sh
|
run: bash DartTest.sh
|
||||||
|
|
||||||
|
build-nim:
|
||||||
|
name: Build Nim
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: flatc
|
||||||
|
# FIXME: make test script not rely on flatc
|
||||||
|
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j
|
||||||
|
- uses: jiro4989/setup-nim-action@v1
|
||||||
|
- name: install library
|
||||||
|
working-directory: nim
|
||||||
|
run: nimble -y develop
|
||||||
|
- name: test
|
||||||
|
working-directory: tests/nim
|
||||||
|
run: python3 testnim.py
|
||||||
|
|
||||||
release-digests:
|
release-digests:
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
needs: [build-linux, build-windows, build-mac-intel, build-mac-universal]
|
needs: [build-linux, build-windows, build-mac-intel, build-mac-universal]
|
||||||
|
|||||||
54
.github/workflows/release.yml
vendored
Normal file
54
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
name: Release
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
|
on:
|
||||||
|
# For manual tests.
|
||||||
|
workflow_dispatch:
|
||||||
|
release:
|
||||||
|
types: [created]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
publish-npm:
|
||||||
|
name: Publish NPM
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: '16.x'
|
||||||
|
registry-url: 'https://registry.npmjs.org'
|
||||||
|
- run: npm publish
|
||||||
|
env:
|
||||||
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
|
||||||
|
publish-pypi:
|
||||||
|
name: Publish PyPi
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: ./python
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.10'
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: |
|
||||||
|
python3 -m pip install --upgrade pip
|
||||||
|
python3 -m pip install setuptools wheel twine
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
python3 setup.py sdist bdist_wheel
|
||||||
|
|
||||||
|
- name: Upload to PyPi
|
||||||
|
run: |
|
||||||
|
python3 -m twine upload dist/*
|
||||||
|
env:
|
||||||
|
TWINE_USERNAME: __token__
|
||||||
|
TWINE_PASSWORD: ${{ secrets.TWINE_TOKEN }}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -4,6 +4,10 @@ All major or breaking changes will be documented in this file, as well as any
|
|||||||
new features that should be highlighted. Minor fixes or improvements are not
|
new features that should be highlighted. Minor fixes or improvements are not
|
||||||
necessarily listed.
|
necessarily listed.
|
||||||
|
|
||||||
|
## 22.10.25 (Oct 25 2002)
|
||||||
|
|
||||||
|
* Added Nim language support with generator and runtime libraries (#7534).
|
||||||
|
|
||||||
## 22.9.29 (Sept 29 2022)
|
## 22.9.29 (Sept 29 2022)
|
||||||
|
|
||||||
* Rust soundness fixes to avoid the crate from bing labelled unsafe (#7518).
|
* Rust soundness fixes to avoid the crate from bing labelled unsafe (#7518).
|
||||||
@@ -27,8 +31,8 @@ necessarily listed.
|
|||||||
`AlignOf()` for structs (#7520).
|
`AlignOf()` for structs (#7520).
|
||||||
|
|
||||||
* C# has an
|
* C# has an
|
||||||
[offical Nuget package](https://www.nuget.org/packages/Google.FlatBuffers) now
|
[official Nuget package](https://www.nuget.org/packages/Google.FlatBuffers)
|
||||||
(#7496).
|
now (#7496).
|
||||||
|
|
||||||
## 2.0.8 (Aug 29 2022)
|
## 2.0.8 (Aug 29 2022)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
set(VERSION_MAJOR 22)
|
set(VERSION_MAJOR 22)
|
||||||
set(VERSION_MINOR 9)
|
set(VERSION_MINOR 10)
|
||||||
set(VERSION_PATCH 29)
|
set(VERSION_PATCH 26)
|
||||||
set(VERSION_COMMIT 0)
|
set(VERSION_COMMIT 0)
|
||||||
|
|
||||||
find_program(GIT git)
|
find_program(GIT git)
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ set(FlatBuffers_Compiler_SRCS
|
|||||||
src/flatc_main.cpp
|
src/flatc_main.cpp
|
||||||
src/bfbs_gen.h
|
src/bfbs_gen.h
|
||||||
src/bfbs_gen_lua.h
|
src/bfbs_gen_lua.h
|
||||||
|
src/bfbs_gen_nim.h
|
||||||
src/bfbs_namer.h
|
src/bfbs_namer.h
|
||||||
include/flatbuffers/code_generators.h
|
include/flatbuffers/code_generators.h
|
||||||
src/binary_annotator.h
|
src/binary_annotator.h
|
||||||
@@ -189,6 +190,7 @@ set(FlatBuffers_Compiler_SRCS
|
|||||||
src/annotated_binary_text_gen.h
|
src/annotated_binary_text_gen.h
|
||||||
src/annotated_binary_text_gen.cpp
|
src/annotated_binary_text_gen.cpp
|
||||||
src/bfbs_gen_lua.cpp
|
src/bfbs_gen_lua.cpp
|
||||||
|
src/bfbs_gen_nim.cpp
|
||||||
src/code_generators.cpp
|
src/code_generators.cpp
|
||||||
grpc/src/compiler/schema_interface.h
|
grpc/src/compiler/schema_interface.h
|
||||||
grpc/src/compiler/cpp_generator.h
|
grpc/src/compiler/cpp_generator.h
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = 'FlatBuffers'
|
s.name = 'FlatBuffers'
|
||||||
s.version = '22.9.29'
|
s.version = '22.10.26'
|
||||||
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
||||||
|
|
||||||
s.description = "FlatBuffers is a cross platform serialization library architected for
|
s.description = "FlatBuffers is a cross platform serialization library architected for
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class Animal : Table() {
|
|||||||
return if(o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
|
return if(o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
|
||||||
}
|
}
|
||||||
companion object {
|
companion object {
|
||||||
fun validateVersion() = Constants.FLATBUFFERS_22_9_29()
|
fun validateVersion() = Constants.FLATBUFFERS_22_10_26()
|
||||||
fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal())
|
fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal())
|
||||||
fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal {
|
fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal {
|
||||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: flat_buffers
|
name: flat_buffers
|
||||||
version: 22.9.29
|
version: 22.10.26
|
||||||
description: FlatBuffers reading and writing library for Dart. Based on original work by Konstantin Scheglov and Paul Berry of the Dart SDK team.
|
description: FlatBuffers reading and writing library for Dart. Based on original work by Konstantin Scheglov and Paul Berry of the Dart SDK team.
|
||||||
homepage: https://github.com/google/flatbuffers
|
homepage: https://github.com/google/flatbuffers
|
||||||
documentation: https://google.github.io/flatbuffers/index.html
|
documentation: https://google.github.io/flatbuffers/index.html
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ include = `include` string\_constant `;`
|
|||||||
|
|
||||||
namespace\_decl = `namespace` ident ( `.` ident )* `;`
|
namespace\_decl = `namespace` ident ( `.` ident )* `;`
|
||||||
|
|
||||||
attribute\_decl = `attribute` ident | `"`ident`"` `;`
|
attribute\_decl = `attribute` ident | `"` ident `"` `;`
|
||||||
|
|
||||||
type\_decl = ( `table` | `struct` ) ident metadata `{` field\_decl+ `}`
|
type\_decl = ( `table` | `struct` ) ident metadata `{` field\_decl+ `}`
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ type = `bool` | `byte` | `ubyte` | `short` | `ushort` | `int` | `uint` |
|
|||||||
`float32` | `float64` |
|
`float32` | `float64` |
|
||||||
`string` | `[` type `]` | ident
|
`string` | `[` type `]` | ident
|
||||||
|
|
||||||
enumval\_decl = ident [ `=` integer\_constant ]
|
enumval\_decl = ident [ `=` integer\_constant ] metadata
|
||||||
|
|
||||||
metadata = [ `(` commasep( ident [ `:` single\_value ] ) `)` ]
|
metadata = [ `(` commasep( ident [ `:` single\_value ] ) `)` ]
|
||||||
|
|
||||||
|
|||||||
@@ -309,11 +309,11 @@ in the corresponding C++ code. Multiple such lines per item are allowed.
|
|||||||
|
|
||||||
### Attributes
|
### Attributes
|
||||||
|
|
||||||
Attributes may be attached to a declaration, behind a field, or after
|
Attributes may be attached to a declaration, behind a field/enum value,
|
||||||
the name of a table/struct/enum/union. These may either have a value or
|
or after the name of a table/struct/enum/union. These may either have
|
||||||
not. Some attributes like `deprecated` are understood by the compiler;
|
a value or not. Some attributes like `deprecated` are understood by
|
||||||
user defined ones need to be declared with the attribute declaration
|
the compiler; user defined ones need to be declared with the attribute
|
||||||
(like `priority` in the example above), and are
|
declaration (like `priority` in the example above), and are
|
||||||
available to query if you parse the schema at runtime.
|
available to query if you parse the schema at runtime.
|
||||||
This is useful if you write your own code generators/editors etc., and
|
This is useful if you write your own code generators/editors etc., and
|
||||||
you wish to add additional information specific to your tool (such as a
|
you wish to add additional information specific to your tool (such as a
|
||||||
@@ -552,7 +552,7 @@ the world. If this is not practical for you, use explicit field ids, which
|
|||||||
should always generate a merge conflict if two people try to allocate the same
|
should always generate a merge conflict if two people try to allocate the same
|
||||||
id.
|
id.
|
||||||
|
|
||||||
### Schema evolution examples
|
### Schema evolution examples (tables)
|
||||||
|
|
||||||
Some examples to clarify what happens as you change a schema:
|
Some examples to clarify what happens as you change a schema:
|
||||||
|
|
||||||
@@ -614,6 +614,41 @@ Occasionally ok. You've renamed fields, which will break all code (and JSON
|
|||||||
files!) that use this schema, but as long as the change is obvious, this is not
|
files!) that use this schema, but as long as the change is obvious, this is not
|
||||||
incompatible with the actual binary buffers, since those only ever address
|
incompatible with the actual binary buffers, since those only ever address
|
||||||
fields by id/offset.
|
fields by id/offset.
|
||||||
|
|
||||||
|
#### Schema evolution examples (unions)
|
||||||
|
|
||||||
|
Suppose we have the following schema:
|
||||||
|
```
|
||||||
|
union Foo { A, B }
|
||||||
|
```
|
||||||
|
We can add another variant at the end.
|
||||||
|
```
|
||||||
|
union Foo { A, B, another_a: A }
|
||||||
|
```
|
||||||
|
and this will be okay. Old code will not recognize `another_a`.
|
||||||
|
However if we add `another_a` anywhere but the end, e.g.
|
||||||
|
```
|
||||||
|
union Foo { A, another_a: A, B }
|
||||||
|
```
|
||||||
|
this is not okay. When new code writes `another_a`, old code will
|
||||||
|
misinterpret it as `B` (and vice versa). However you can explicitly
|
||||||
|
set the union's "discriminant" value like so:
|
||||||
|
```
|
||||||
|
union Foo { A = 1, another_a: A = 3, B = 2 }
|
||||||
|
```
|
||||||
|
This is okay.
|
||||||
|
|
||||||
|
```
|
||||||
|
union Foo { original_a: A = 1, another_a: A = 3, B = 2 }
|
||||||
|
```
|
||||||
|
Renaming fields will break code and any saved human readable representations,
|
||||||
|
such as json files, but the binary buffers will be the same.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
### Testing whether a field is present in a table
|
### Testing whether a field is present in a table
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import FlatBuffers
|
|||||||
|
|
||||||
public struct models_HelloReply: FlatBufferObject, Verifiable {
|
public struct models_HelloReply: FlatBufferObject, Verifiable {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_22_9_29() }
|
static func validateVersion() { FlatBuffersVersion_22_10_26() }
|
||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ extension models_HelloReply: Encodable {
|
|||||||
|
|
||||||
public struct models_HelloRequest: FlatBufferObject, Verifiable {
|
public struct models_HelloRequest: FlatBufferObject, Verifiable {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_22_9_29() }
|
static func validateVersion() { FlatBuffersVersion_22_10_26() }
|
||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ template<typename T, uint16_t length> class Array {
|
|||||||
public:
|
public:
|
||||||
typedef uint16_t size_type;
|
typedef uint16_t size_type;
|
||||||
typedef typename IndirectHelper<IndirectHelperType>::return_type return_type;
|
typedef typename IndirectHelper<IndirectHelperType>::return_type return_type;
|
||||||
typedef VectorIterator<T, return_type> const_iterator;
|
typedef VectorConstIterator<T, return_type> const_iterator;
|
||||||
typedef VectorReverseIterator<const_iterator> const_reverse_iterator;
|
typedef VectorReverseIterator<const_iterator> const_reverse_iterator;
|
||||||
|
|
||||||
// If T is a LE-scalar or a struct (!scalar_tag::value).
|
// If T is a LE-scalar or a struct (!scalar_tag::value).
|
||||||
|
|||||||
@@ -139,8 +139,8 @@
|
|||||||
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
|
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
|
||||||
|
|
||||||
#define FLATBUFFERS_VERSION_MAJOR 22
|
#define FLATBUFFERS_VERSION_MAJOR 22
|
||||||
#define FLATBUFFERS_VERSION_MINOR 9
|
#define FLATBUFFERS_VERSION_MINOR 10
|
||||||
#define FLATBUFFERS_VERSION_REVISION 29
|
#define FLATBUFFERS_VERSION_REVISION 26
|
||||||
#define FLATBUFFERS_STRING_EXPAND(X) #X
|
#define FLATBUFFERS_STRING_EXPAND(X) #X
|
||||||
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
|
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
|
||||||
namespace flatbuffers {
|
namespace flatbuffers {
|
||||||
|
|||||||
@@ -76,6 +76,9 @@ template<typename T> struct IndirectHelper {
|
|||||||
static return_type Read(const uint8_t *p, uoffset_t i) {
|
static return_type Read(const uint8_t *p, uoffset_t i) {
|
||||||
return EndianScalar((reinterpret_cast<const T *>(p))[i]);
|
return EndianScalar((reinterpret_cast<const T *>(p))[i]);
|
||||||
}
|
}
|
||||||
|
static return_type Read(uint8_t *p, uoffset_t i) {
|
||||||
|
return Read(const_cast<const uint8_t *>(p), i);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
template<typename T> struct IndirectHelper<Offset<T>> {
|
template<typename T> struct IndirectHelper<Offset<T>> {
|
||||||
typedef const T *return_type;
|
typedef const T *return_type;
|
||||||
@@ -85,13 +88,20 @@ template<typename T> struct IndirectHelper<Offset<T>> {
|
|||||||
p += i * sizeof(uoffset_t);
|
p += i * sizeof(uoffset_t);
|
||||||
return reinterpret_cast<return_type>(p + ReadScalar<uoffset_t>(p));
|
return reinterpret_cast<return_type>(p + ReadScalar<uoffset_t>(p));
|
||||||
}
|
}
|
||||||
|
static mutable_return_type Read(uint8_t *p, uoffset_t i) {
|
||||||
|
p += i * sizeof(uoffset_t);
|
||||||
|
return reinterpret_cast<mutable_return_type>(p + ReadScalar<uoffset_t>(p));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
template<typename T> struct IndirectHelper<const T *> {
|
template<typename T> struct IndirectHelper<const T *> {
|
||||||
typedef const T *return_type;
|
typedef const T *return_type;
|
||||||
typedef T *mutable_return_type;
|
typedef T *mutable_return_type;
|
||||||
static const size_t element_stride = sizeof(T);
|
static const size_t element_stride = sizeof(T);
|
||||||
static return_type Read(const uint8_t *p, uoffset_t i) {
|
static return_type Read(const uint8_t *p, uoffset_t i) {
|
||||||
return reinterpret_cast<const T *>(p + i * sizeof(T));
|
return reinterpret_cast<return_type>(p + i * sizeof(T));
|
||||||
|
}
|
||||||
|
static mutable_return_type Read(uint8_t *p, uoffset_t i) {
|
||||||
|
return reinterpret_cast<mutable_return_type>(p + i * sizeof(T));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -382,7 +382,14 @@ struct EnumVal {
|
|||||||
Offset<reflection::EnumVal> Serialize(FlatBufferBuilder *builder,
|
Offset<reflection::EnumVal> Serialize(FlatBufferBuilder *builder,
|
||||||
const Parser &parser) const;
|
const Parser &parser) const;
|
||||||
|
|
||||||
bool Deserialize(const Parser &parser, const reflection::EnumVal *val);
|
bool Deserialize(Parser &parser, const reflection::EnumVal *val);
|
||||||
|
|
||||||
|
flatbuffers::Offset<
|
||||||
|
flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>>
|
||||||
|
SerializeAttributes(FlatBufferBuilder *builder, const Parser &parser) const;
|
||||||
|
|
||||||
|
bool DeserializeAttributes(Parser &parser,
|
||||||
|
const Vector<Offset<reflection::KeyValue>> *attrs);
|
||||||
|
|
||||||
uint64_t GetAsUInt64() const { return static_cast<uint64_t>(value); }
|
uint64_t GetAsUInt64() const { return static_cast<uint64_t>(value); }
|
||||||
int64_t GetAsInt64() const { return value; }
|
int64_t GetAsInt64() const { return value; }
|
||||||
@@ -392,6 +399,7 @@ struct EnumVal {
|
|||||||
std::string name;
|
std::string name;
|
||||||
std::vector<std::string> doc_comment;
|
std::vector<std::string> doc_comment;
|
||||||
Type union_type;
|
Type union_type;
|
||||||
|
SymbolTable<Value> attributes;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend EnumDef;
|
friend EnumDef;
|
||||||
@@ -653,6 +661,7 @@ struct IDLOptions {
|
|||||||
kRust = 1 << 14,
|
kRust = 1 << 14,
|
||||||
kKotlin = 1 << 15,
|
kKotlin = 1 << 15,
|
||||||
kSwift = 1 << 16,
|
kSwift = 1 << 16,
|
||||||
|
kNim = 1 << 17,
|
||||||
kMAX
|
kMAX
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||||
// generated, otherwise it may not be compatible.
|
// generated, otherwise it may not be compatible.
|
||||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 22 &&
|
static_assert(FLATBUFFERS_VERSION_MAJOR == 22 &&
|
||||||
FLATBUFFERS_VERSION_MINOR == 9 &&
|
FLATBUFFERS_VERSION_MINOR == 10 &&
|
||||||
FLATBUFFERS_VERSION_REVISION == 29,
|
FLATBUFFERS_VERSION_REVISION == 26,
|
||||||
"Non-compatible flatbuffers version included");
|
"Non-compatible flatbuffers version included");
|
||||||
|
|
||||||
namespace reflection {
|
namespace reflection {
|
||||||
@@ -334,7 +334,8 @@ struct EnumVal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
VT_NAME = 4,
|
VT_NAME = 4,
|
||||||
VT_VALUE = 6,
|
VT_VALUE = 6,
|
||||||
VT_UNION_TYPE = 10,
|
VT_UNION_TYPE = 10,
|
||||||
VT_DOCUMENTATION = 12
|
VT_DOCUMENTATION = 12,
|
||||||
|
VT_ATTRIBUTES = 14
|
||||||
};
|
};
|
||||||
const flatbuffers::String *name() const {
|
const flatbuffers::String *name() const {
|
||||||
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
||||||
@@ -354,6 +355,9 @@ struct EnumVal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *documentation() const {
|
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *documentation() const {
|
||||||
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *>(VT_DOCUMENTATION);
|
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *>(VT_DOCUMENTATION);
|
||||||
}
|
}
|
||||||
|
const flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>> *attributes() const {
|
||||||
|
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>> *>(VT_ATTRIBUTES);
|
||||||
|
}
|
||||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyOffsetRequired(verifier, VT_NAME) &&
|
VerifyOffsetRequired(verifier, VT_NAME) &&
|
||||||
@@ -364,6 +368,9 @@ struct EnumVal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
VerifyOffset(verifier, VT_DOCUMENTATION) &&
|
VerifyOffset(verifier, VT_DOCUMENTATION) &&
|
||||||
verifier.VerifyVector(documentation()) &&
|
verifier.VerifyVector(documentation()) &&
|
||||||
verifier.VerifyVectorOfStrings(documentation()) &&
|
verifier.VerifyVectorOfStrings(documentation()) &&
|
||||||
|
VerifyOffset(verifier, VT_ATTRIBUTES) &&
|
||||||
|
verifier.VerifyVector(attributes()) &&
|
||||||
|
verifier.VerifyVectorOfTables(attributes()) &&
|
||||||
verifier.EndTable();
|
verifier.EndTable();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -384,6 +391,9 @@ struct EnumValBuilder {
|
|||||||
void add_documentation(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation) {
|
void add_documentation(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation) {
|
||||||
fbb_.AddOffset(EnumVal::VT_DOCUMENTATION, documentation);
|
fbb_.AddOffset(EnumVal::VT_DOCUMENTATION, documentation);
|
||||||
}
|
}
|
||||||
|
void add_attributes(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>> attributes) {
|
||||||
|
fbb_.AddOffset(EnumVal::VT_ATTRIBUTES, attributes);
|
||||||
|
}
|
||||||
explicit EnumValBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
explicit EnumValBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
: fbb_(_fbb) {
|
: fbb_(_fbb) {
|
||||||
start_ = fbb_.StartTable();
|
start_ = fbb_.StartTable();
|
||||||
@@ -401,9 +411,11 @@ inline flatbuffers::Offset<EnumVal> CreateEnumVal(
|
|||||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
flatbuffers::Offset<flatbuffers::String> name = 0,
|
||||||
int64_t value = 0,
|
int64_t value = 0,
|
||||||
flatbuffers::Offset<reflection::Type> union_type = 0,
|
flatbuffers::Offset<reflection::Type> union_type = 0,
|
||||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation = 0) {
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation = 0,
|
||||||
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>> attributes = 0) {
|
||||||
EnumValBuilder builder_(_fbb);
|
EnumValBuilder builder_(_fbb);
|
||||||
builder_.add_value(value);
|
builder_.add_value(value);
|
||||||
|
builder_.add_attributes(attributes);
|
||||||
builder_.add_documentation(documentation);
|
builder_.add_documentation(documentation);
|
||||||
builder_.add_union_type(union_type);
|
builder_.add_union_type(union_type);
|
||||||
builder_.add_name(name);
|
builder_.add_name(name);
|
||||||
@@ -415,15 +427,18 @@ inline flatbuffers::Offset<EnumVal> CreateEnumValDirect(
|
|||||||
const char *name = nullptr,
|
const char *name = nullptr,
|
||||||
int64_t value = 0,
|
int64_t value = 0,
|
||||||
flatbuffers::Offset<reflection::Type> union_type = 0,
|
flatbuffers::Offset<reflection::Type> union_type = 0,
|
||||||
const std::vector<flatbuffers::Offset<flatbuffers::String>> *documentation = nullptr) {
|
const std::vector<flatbuffers::Offset<flatbuffers::String>> *documentation = nullptr,
|
||||||
|
std::vector<flatbuffers::Offset<reflection::KeyValue>> *attributes = nullptr) {
|
||||||
auto name__ = name ? _fbb.CreateString(name) : 0;
|
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||||
auto documentation__ = documentation ? _fbb.CreateVector<flatbuffers::Offset<flatbuffers::String>>(*documentation) : 0;
|
auto documentation__ = documentation ? _fbb.CreateVector<flatbuffers::Offset<flatbuffers::String>>(*documentation) : 0;
|
||||||
|
auto attributes__ = attributes ? _fbb.CreateVectorOfSortedTables<reflection::KeyValue>(attributes) : 0;
|
||||||
return reflection::CreateEnumVal(
|
return reflection::CreateEnumVal(
|
||||||
_fbb,
|
_fbb,
|
||||||
name__,
|
name__,
|
||||||
value,
|
value,
|
||||||
union_type,
|
union_type,
|
||||||
documentation__);
|
documentation__,
|
||||||
|
attributes__);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Enum FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
struct Enum FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||||
|
|||||||
@@ -27,14 +27,15 @@ struct String;
|
|||||||
|
|
||||||
// An STL compatible iterator implementation for Vector below, effectively
|
// An STL compatible iterator implementation for Vector below, effectively
|
||||||
// calling Get() for every element.
|
// calling Get() for every element.
|
||||||
template<typename T, typename IT> struct VectorIterator {
|
template<typename T, typename IT, typename Data = uint8_t *>
|
||||||
|
struct VectorIterator {
|
||||||
typedef std::random_access_iterator_tag iterator_category;
|
typedef std::random_access_iterator_tag iterator_category;
|
||||||
typedef IT value_type;
|
typedef IT value_type;
|
||||||
typedef ptrdiff_t difference_type;
|
typedef ptrdiff_t difference_type;
|
||||||
typedef IT *pointer;
|
typedef IT *pointer;
|
||||||
typedef IT &reference;
|
typedef IT &reference;
|
||||||
|
|
||||||
VectorIterator(const uint8_t *data, uoffset_t i)
|
VectorIterator(Data data, uoffset_t i)
|
||||||
: data_(data + IndirectHelper<T>::element_stride * i) {}
|
: data_(data + IndirectHelper<T>::element_stride * i) {}
|
||||||
VectorIterator(const VectorIterator &other) : data_(other.data_) {}
|
VectorIterator(const VectorIterator &other) : data_(other.data_) {}
|
||||||
VectorIterator() : data_(nullptr) {}
|
VectorIterator() : data_(nullptr) {}
|
||||||
@@ -116,9 +117,12 @@ template<typename T, typename IT> struct VectorIterator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const uint8_t *data_;
|
Data data_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T, typename IT>
|
||||||
|
using VectorConstIterator = VectorIterator<T, IT, const uint8_t *>;
|
||||||
|
|
||||||
template<typename Iterator>
|
template<typename Iterator>
|
||||||
struct VectorReverseIterator : public std::reverse_iterator<Iterator> {
|
struct VectorReverseIterator : public std::reverse_iterator<Iterator> {
|
||||||
explicit VectorReverseIterator(Iterator iter)
|
explicit VectorReverseIterator(Iterator iter)
|
||||||
@@ -145,7 +149,7 @@ template<typename T> class Vector {
|
|||||||
public:
|
public:
|
||||||
typedef VectorIterator<T, typename IndirectHelper<T>::mutable_return_type>
|
typedef VectorIterator<T, typename IndirectHelper<T>::mutable_return_type>
|
||||||
iterator;
|
iterator;
|
||||||
typedef VectorIterator<T, typename IndirectHelper<T>::return_type>
|
typedef VectorConstIterator<T, typename IndirectHelper<T>::return_type>
|
||||||
const_iterator;
|
const_iterator;
|
||||||
typedef VectorReverseIterator<iterator> reverse_iterator;
|
typedef VectorReverseIterator<iterator> reverse_iterator;
|
||||||
typedef VectorReverseIterator<const_iterator> const_reverse_iterator;
|
typedef VectorReverseIterator<const_iterator> const_reverse_iterator;
|
||||||
|
|||||||
35
java/pom.xml
35
java/pom.xml
@@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.google.flatbuffers</groupId>
|
<groupId>com.google.flatbuffers</groupId>
|
||||||
<artifactId>flatbuffers-java</artifactId>
|
<artifactId>flatbuffers-java</artifactId>
|
||||||
<version>22.9.29</version>
|
<version>22.10.26</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>FlatBuffers Java API</name>
|
<name>FlatBuffers Java API</name>
|
||||||
<description>
|
<description>
|
||||||
@@ -58,19 +58,17 @@
|
|||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<release>8</release>
|
<release>8</release>
|
||||||
<testExcludes>
|
<testExcludes>
|
||||||
<testExclude>**/LongEnum.java</testExclude>
|
<testExclude>MyGame/Example/MonsterStorageGrpc.java</testExclude>
|
||||||
<testExclude>MyGame/Example/MonsterStorageGrpc.java</testExclude>
|
<testExclude>MyGame/OtherNameSpace/TableBT.java</testExclude>
|
||||||
<testExclude>MyGame/Example/StructOfStructs**</testExclude>
|
</testExcludes>
|
||||||
<testExclude>MyGame/OtherNameSpace/TableBT.java</testExclude>
|
</configuration>
|
||||||
</testExcludes>
|
<version>3.8.1</version>
|
||||||
</configuration>
|
</plugin>
|
||||||
<version>3.8.1</version>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<profiles>
|
<profiles>
|
||||||
@@ -149,10 +147,10 @@
|
|||||||
<goal>sign</goal>
|
<goal>sign</goal>
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<gpgArguments>
|
<gpgArguments>
|
||||||
<arg>--pinentry-mode</arg>
|
<arg>--pinentry-mode</arg>
|
||||||
<arg>loopback</arg>
|
<arg>loopback</arg>
|
||||||
</gpgArguments>
|
</gpgArguments>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
@@ -173,4 +171,3 @@
|
|||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class Constants {
|
|||||||
Changes to the Java implementation need to be sure to change
|
Changes to the Java implementation need to be sure to change
|
||||||
the version here and in the code generator on every possible
|
the version here and in the code generator on every possible
|
||||||
incompatible change */
|
incompatible change */
|
||||||
public static void FLATBUFFERS_22_9_29() {}
|
public static void FLATBUFFERS_22_10_26() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @endcond
|
/// @endcond
|
||||||
|
|||||||
@@ -32,6 +32,6 @@ namespace Google.FlatBuffers
|
|||||||
Changes to the C# implementation need to be sure to change
|
Changes to the C# implementation need to be sure to change
|
||||||
the version here and in the code generator on every possible
|
the version here and in the code generator on every possible
|
||||||
incompatible change */
|
incompatible change */
|
||||||
public static void FLATBUFFERS_22_9_29() {}
|
public static void FLATBUFFERS_22_10_26() {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netstandard2.1;netstandard2.0;net46</TargetFrameworks>
|
<TargetFrameworks>netstandard2.1;netstandard2.0;net46</TargetFrameworks>
|
||||||
<Description>A cross-platform memory efficient serialization library</Description>
|
<Description>A cross-platform memory efficient serialization library</Description>
|
||||||
<PackageVersion>22.9.29</PackageVersion>
|
<PackageVersion>22.10.26</PackageVersion>
|
||||||
<Authors>Google LLC</Authors>
|
<Authors>Google LLC</Authors>
|
||||||
<PackageProjectUrl>https://github.com/google/flatbuffers</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/google/flatbuffers</PackageProjectUrl>
|
||||||
<RepositoryUrl>https://github.com/google/flatbuffers</RepositoryUrl>
|
<RepositoryUrl>https://github.com/google/flatbuffers</RepositoryUrl>
|
||||||
|
|||||||
7
nim/flatbuffers.nimble
Normal file
7
nim/flatbuffers.nimble
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
version = "2.0.8"
|
||||||
|
author = "flatbuffers"
|
||||||
|
description = "Flatbuffers"
|
||||||
|
license = "Apache 2.0"
|
||||||
|
srcDir = "flatbuffers"
|
||||||
|
|
||||||
|
requires "nim >= 1.4.0"
|
||||||
7
nim/flatbuffers/flatbuffers.nim
Normal file
7
nim/flatbuffers/flatbuffers.nim
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import
|
||||||
|
src/[
|
||||||
|
builder,
|
||||||
|
struct,
|
||||||
|
table
|
||||||
|
]
|
||||||
|
export flatbuffers.builder, flatbuffers.table, flatbuffers.struct
|
||||||
262
nim/flatbuffers/src/builder.nim
Normal file
262
nim/flatbuffers/src/builder.nim
Normal file
@@ -0,0 +1,262 @@
|
|||||||
|
import math
|
||||||
|
import table
|
||||||
|
|
||||||
|
|
||||||
|
const MAX_BUFFER_SIZE* = 2^31
|
||||||
|
|
||||||
|
|
||||||
|
type Builder* = ref object of RootObj
|
||||||
|
bytes*: seq[byte]
|
||||||
|
minalign*: int
|
||||||
|
current_vtable*: seq[uoffset]
|
||||||
|
objectEnd*: uoffset
|
||||||
|
vtables*: seq[uoffset] #?
|
||||||
|
head*: uoffset
|
||||||
|
nested*: bool
|
||||||
|
finished*: bool
|
||||||
|
vectorNumElems*: uoffset
|
||||||
|
|
||||||
|
using this: var Builder
|
||||||
|
|
||||||
|
func newBuilder*(size: int): Builder =
|
||||||
|
result = new Builder
|
||||||
|
result.bytes.setLen(size)
|
||||||
|
result.minalign = 1
|
||||||
|
result.head = size.uoffset
|
||||||
|
result.nested = false
|
||||||
|
result.finished = false
|
||||||
|
result.vectorNumElems = 0
|
||||||
|
|
||||||
|
proc FinishedBytes*(this): seq[byte] =
|
||||||
|
if not this.finished:
|
||||||
|
quit("Builder not finished, Incorrect use of FinishedBytes(): must call 'Finish' first.")
|
||||||
|
result = this.bytes[this.head..^1]
|
||||||
|
|
||||||
|
proc Output*(this): seq[byte] =
|
||||||
|
if not this.finished:
|
||||||
|
quit("Builder not finished, Incorrect use of Output(): must call 'Finish' first.")
|
||||||
|
|
||||||
|
result = this.bytes[this.head..^1]
|
||||||
|
|
||||||
|
func Offset*(this): uoffset =
|
||||||
|
result = this.bytes.len.uoffset - this.head
|
||||||
|
|
||||||
|
proc StartObject*(this; numfields: int) =
|
||||||
|
if this.nested:
|
||||||
|
quit("builder is nested")
|
||||||
|
|
||||||
|
this.current_vtable.setLen(numfields)
|
||||||
|
for i in this.current_vtable.mitems():
|
||||||
|
i = 0
|
||||||
|
this.objectEnd = this.Offset()
|
||||||
|
this.nested = true
|
||||||
|
|
||||||
|
proc GrowByteBuffer*(this) =
|
||||||
|
if this.bytes.len == MAX_BUFFER_SIZE:
|
||||||
|
quit("flatbuffers: cannot grow buffer beyond 2 gigabytes")
|
||||||
|
let oldLen = this.bytes.len
|
||||||
|
var newLen = min(this.bytes.len * 2, MAX_BUFFER_SIZE)
|
||||||
|
if newLen == 0:
|
||||||
|
newLen = 1
|
||||||
|
this.bytes.setLen(newLen)
|
||||||
|
var j = this.bytes.len - 1
|
||||||
|
while j >= 0:
|
||||||
|
if j >= newLen - oldLen:
|
||||||
|
this.bytes[j] = this.bytes[j - (newLen - oldLen)]
|
||||||
|
else:
|
||||||
|
this.bytes[j] = 0
|
||||||
|
dec(j)
|
||||||
|
|
||||||
|
proc Place*[T](this; x: T) =
|
||||||
|
this.head -= uoffset x.sizeof
|
||||||
|
WriteVal(this.bytes, this.head, x)
|
||||||
|
|
||||||
|
func Pad*(this; n: int) =
|
||||||
|
for i in 0..<n:
|
||||||
|
this.Place(0.byte)
|
||||||
|
|
||||||
|
proc Prep*(this; size: int; additionalBytes: int) =
|
||||||
|
if size > this.minalign:
|
||||||
|
this.minalign = size
|
||||||
|
var alignsize = (not (this.bytes.len - this.head.int + additionalBytes)) + 1
|
||||||
|
alignsize = alignsize and (size - 1)
|
||||||
|
|
||||||
|
while this.head.int < alignsize + size + additionalBytes:
|
||||||
|
let oldbufSize = this.bytes.len
|
||||||
|
this.GrowByteBuffer()
|
||||||
|
this.head = (this.head.int + this.bytes.len - oldbufSize).uoffset
|
||||||
|
this.Pad(alignsize)
|
||||||
|
|
||||||
|
proc PrependOffsetRelative*[T: Offsets](this; off: T) =
|
||||||
|
when T is voffset:
|
||||||
|
this.Prep(T.sizeof, 0)
|
||||||
|
if not off.uoffset <= this.Offset:
|
||||||
|
quit("flatbuffers: Offset arithmetic error.")
|
||||||
|
this.Place(off)
|
||||||
|
else:
|
||||||
|
this.Prep(T.sizeof, 0)
|
||||||
|
if not off.uoffset <= this.Offset:
|
||||||
|
quit("flatbuffers: Offset arithmetic error.")
|
||||||
|
let off2: T = this.Offset.T - off + sizeof(T).T
|
||||||
|
this.Place(off2)
|
||||||
|
|
||||||
|
|
||||||
|
proc Prepend*[T](this; x: T) =
|
||||||
|
this.Prep(x.sizeof, 0)
|
||||||
|
this.Place(x)
|
||||||
|
|
||||||
|
proc Slot*(this; slotnum: int) =
|
||||||
|
this.current_vtable[slotnum] = this.Offset
|
||||||
|
|
||||||
|
proc PrependSlot*[T](this; o: int; x, d: T) =
|
||||||
|
if x != d:
|
||||||
|
when T is uoffset or T is soffset or T is voffset:
|
||||||
|
this.PrependOffsetRelative(x)
|
||||||
|
else:
|
||||||
|
this.Prepend(x)
|
||||||
|
this.Slot(o)
|
||||||
|
|
||||||
|
proc AssertStuctInline(this; obj: uoffset) =
|
||||||
|
if obj != this.Offset:
|
||||||
|
quit("flatbuffers: Tried to write a Struct at an Offset that is different from the current Offset of the Builder.")
|
||||||
|
|
||||||
|
proc PrependStructSlot*(this; o: int; x: uoffset; d: uoffset) =
|
||||||
|
if x != d:
|
||||||
|
this.AssertStuctInline(x)
|
||||||
|
this.Slot(o)
|
||||||
|
|
||||||
|
proc Add*[T](this; n: T) =
|
||||||
|
this.Prep(T.sizeof, 0)
|
||||||
|
WriteVal(this.bytes, this.head, n)
|
||||||
|
|
||||||
|
proc VtableEqual*(a: seq[uoffset]; objectStart: uoffset; b: seq[byte]): bool =
|
||||||
|
if a.len * voffset.sizeof != b.len:
|
||||||
|
return false
|
||||||
|
|
||||||
|
var i = 0
|
||||||
|
while i < a.len:
|
||||||
|
var seq = b[i * voffset.sizeof..<(i + 1) * voffset.sizeof]
|
||||||
|
let x = GetVal[voffset](addr seq)
|
||||||
|
|
||||||
|
if x == 0 and a[i] == 0:
|
||||||
|
inc i
|
||||||
|
continue
|
||||||
|
|
||||||
|
let y = objectStart.soffset - a[i].soffset
|
||||||
|
if x.soffset != y:
|
||||||
|
return false
|
||||||
|
inc i
|
||||||
|
return true
|
||||||
|
|
||||||
|
proc WriteVtable*(this): uoffset =
|
||||||
|
this.PrependOffsetRelative(0.soffset)
|
||||||
|
|
||||||
|
let objectOffset = this.Offset
|
||||||
|
var existingVtable = uoffset 0
|
||||||
|
|
||||||
|
var i = this.current_vtable.len - 1
|
||||||
|
while i >= 0 and this.current_vtable[i] == 0: dec i
|
||||||
|
|
||||||
|
this.current_vtable = this.current_vtable[0..i]
|
||||||
|
for i in countdown(this.vtables.len - 1, 0):
|
||||||
|
let
|
||||||
|
vt2Offset: uoffset = this.vtables[i]
|
||||||
|
vt2Start: int = this.bytes.len - int vt2Offset
|
||||||
|
|
||||||
|
var seq = this.bytes[vt2Start..<this.bytes.len]
|
||||||
|
let
|
||||||
|
vt2Len = GetVal[voffset](addr seq)
|
||||||
|
metadata = 2 * voffset.sizeof # VtableMetadataFields * SizeVOffsetT
|
||||||
|
vt2End = vt2Start + vt2Len.int
|
||||||
|
vt2 = this.bytes[this.bytes.len - vt2Offset.int + metadata..<vt2End]
|
||||||
|
|
||||||
|
if VtableEqual(this.current_vtable, objectOffset, vt2):
|
||||||
|
existingVtable = vt2Offset
|
||||||
|
break
|
||||||
|
|
||||||
|
if existingVtable == 0:
|
||||||
|
for i in countdown(this.current_vtable.len - 1, 0):
|
||||||
|
var off: uoffset
|
||||||
|
if this.current_vtable[i] != 0:
|
||||||
|
off = objectOffset - this.current_vtable[i]
|
||||||
|
|
||||||
|
this.PrependOffsetRelative(off.voffset)
|
||||||
|
|
||||||
|
let objectSize = objectOffset - this.objectEnd
|
||||||
|
this.PrependOffsetRelative(objectSize.voffset)
|
||||||
|
|
||||||
|
let vBytes = (this.current_vtable.len + 2) * voffset.sizeof
|
||||||
|
this.PrependOffsetRelative(vBytes.voffset)
|
||||||
|
|
||||||
|
let objectStart: uoffset = (this.bytes.len.uoffset - objectOffset)
|
||||||
|
WriteVal(this.bytes, objectStart, (this.Offset - objectOffset).soffset)
|
||||||
|
this.vtables.add this.Offset
|
||||||
|
else:
|
||||||
|
let objectStart: uoffset = this.bytes.len.uoffset - objectOffset
|
||||||
|
this.head = objectStart
|
||||||
|
WriteVal(this.bytes, this.head,
|
||||||
|
(existingVtable.soffset - objectOffset.soffset))
|
||||||
|
|
||||||
|
this.current_vtable = @[]
|
||||||
|
result = objectOffset
|
||||||
|
|
||||||
|
proc EndObject*(this): uoffset =
|
||||||
|
if not this.nested:
|
||||||
|
quit("builder is not nested")
|
||||||
|
result = this.WriteVtable()
|
||||||
|
this.nested = false
|
||||||
|
|
||||||
|
proc End*(this: var Builder): uoffset =
|
||||||
|
result = this.EndObject()
|
||||||
|
|
||||||
|
proc StartVector*(this; elemSize: int; numElems: uoffset;
|
||||||
|
alignment: int) =
|
||||||
|
if this.nested:
|
||||||
|
quit("builder is nested")
|
||||||
|
this.nested = true
|
||||||
|
this.vectorNumElems = numElems
|
||||||
|
this.Prep(sizeof(uint32), elemSize * numElems.int)
|
||||||
|
this.Prep(alignment, elemSize * numElems.int)
|
||||||
|
|
||||||
|
proc EndVector*(this): uoffset =
|
||||||
|
if not this.nested:
|
||||||
|
quit("builder is not nested")
|
||||||
|
this.nested = false
|
||||||
|
this.Place(this.vectorNumElems)
|
||||||
|
this.vectorNumElems = 0
|
||||||
|
result = this.Offset
|
||||||
|
|
||||||
|
proc getChars*(str: seq[byte]): string =
|
||||||
|
var bytes = str
|
||||||
|
result = GetVal[string](addr bytes)
|
||||||
|
|
||||||
|
proc getBytes*(str: string | cstring): seq[byte] =
|
||||||
|
for chr in str:
|
||||||
|
result.add byte chr
|
||||||
|
result.add byte 0
|
||||||
|
|
||||||
|
proc Create*[T](this; s: T): uoffset = # Both CreateString and CreateByteVector functionality
|
||||||
|
if this.nested:
|
||||||
|
quit("builder is nested")
|
||||||
|
this.nested = true
|
||||||
|
when T is cstring or T is string:
|
||||||
|
let x = s.getBytes()
|
||||||
|
let l = x.len.uoffset
|
||||||
|
this.vectorNumElems = l-1
|
||||||
|
else:
|
||||||
|
let x = s
|
||||||
|
let l = x.len.uoffset
|
||||||
|
this.vectorNumElems = l
|
||||||
|
this.Prep(uoffset.sizeof, l.int * byte.sizeof)
|
||||||
|
this.head -= l
|
||||||
|
this.bytes[this.head..<this.head+l] = x
|
||||||
|
result = this.EndVector()
|
||||||
|
|
||||||
|
proc Finish*(this; rootTable: uoffset) =
|
||||||
|
if this.nested:
|
||||||
|
quit("builder is nested")
|
||||||
|
this.nested = true
|
||||||
|
|
||||||
|
this.Prep(this.minalign, uoffset.sizeof)
|
||||||
|
this.PrependOffsetRelative(rootTable)
|
||||||
|
this.finished = true
|
||||||
12
nim/flatbuffers/src/endian.nim
Normal file
12
nim/flatbuffers/src/endian.nim
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
template swapEndian*(outp, inp: pointer, size: int) =
|
||||||
|
var i = cast[cstring](inp)
|
||||||
|
var o = cast[cstring](outp)
|
||||||
|
for x in 0..<size:
|
||||||
|
o[x] = i[(0..<size).len - x - 1]
|
||||||
|
|
||||||
|
when system.cpuEndian == bigEndian:
|
||||||
|
func littleEndianX*(outp, inp: pointer, size: int) {.inline.} = swapEndian(outp, inp, size)
|
||||||
|
func bigEndianX*(outp, inp: pointer, size: int) {.inline.} = copyMem(outp, inp, size)
|
||||||
|
else:
|
||||||
|
func littleEndianX*(outp, inp: pointer, size: int) {.inline.} = copyMem(outp, inp, size)
|
||||||
|
func bigEndianX*(outp, inp: pointer, size: int) {.inline.} = swapEndian(outp, inp, size)
|
||||||
24
nim/flatbuffers/src/struct.nim
Normal file
24
nim/flatbuffers/src/struct.nim
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import table
|
||||||
|
|
||||||
|
|
||||||
|
type FlatObj* {.inheritable.} = object
|
||||||
|
tab*: Vtable
|
||||||
|
|
||||||
|
func Table*(this: var FlatObj): Vtable = this.tab
|
||||||
|
|
||||||
|
func Init*(this: var FlatObj; buf: seq[byte]; i: uoffset) =
|
||||||
|
this.tab.Bytes = buf
|
||||||
|
this.tab.Pos = i
|
||||||
|
|
||||||
|
# Cant define it in table.nim since it needs FlatObj and Init
|
||||||
|
func GetUnion*[T: FlatObj](this: var Vtable; off: uoffset): T =
|
||||||
|
result.Init(this.Bytes, this.Indirect(off))
|
||||||
|
|
||||||
|
func GetRootAs*(result: var FlatObj; buf: seq[byte]; offset: uoffset) =
|
||||||
|
var
|
||||||
|
vtable = Vtable(Bytes: buf[offset..^1], Pos: offset)
|
||||||
|
n = Get[uoffset](vtable, offset)
|
||||||
|
result.Init(buf, n+offset)
|
||||||
|
|
||||||
|
func GetRootAs*(result: var FlatObj; buf: string; offset: uoffset) =
|
||||||
|
result.GetRootAs(cast[seq[byte]](buf), offset)
|
||||||
149
nim/flatbuffers/src/table.nim
Normal file
149
nim/flatbuffers/src/table.nim
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
import endian
|
||||||
|
|
||||||
|
|
||||||
|
type
|
||||||
|
uoffset* = uint32 ## offset in to the buffer
|
||||||
|
soffset* = int32 ## offset from start of table, to a vtable
|
||||||
|
voffset* = uint16 ## offset from start of table to value
|
||||||
|
|
||||||
|
type Offsets* = uoffset | soffset | voffset
|
||||||
|
|
||||||
|
type Vtable* = object
|
||||||
|
Bytes*: seq[byte]
|
||||||
|
Pos*: uoffset
|
||||||
|
|
||||||
|
|
||||||
|
using this: Vtable
|
||||||
|
|
||||||
|
|
||||||
|
func GetVal*[T](b: ptr seq[byte]): T {.inline.} =
|
||||||
|
when T is float64:
|
||||||
|
result = cast[T](GetVal[uint64](b))
|
||||||
|
elif T is float32:
|
||||||
|
result = cast[T](GetVal[uint32](b))
|
||||||
|
elif T is string:
|
||||||
|
result = cast[T](b[])
|
||||||
|
else:
|
||||||
|
if b[].len < T.sizeof:
|
||||||
|
b[].setLen T.sizeof
|
||||||
|
result = cast[ptr T](unsafeAddr b[][0])[]
|
||||||
|
|
||||||
|
|
||||||
|
template Get*[T](this; off: uoffset): T =
|
||||||
|
var seq = this.Bytes[off..^1]
|
||||||
|
GetVal[T](addr seq)
|
||||||
|
|
||||||
|
template Get*[T](this; off: soffset): T =
|
||||||
|
var seq = this.Bytes[off..^1]
|
||||||
|
GetVal[T](addr seq)
|
||||||
|
|
||||||
|
template Get*[T](this; off: voffset): T =
|
||||||
|
var seq = this.Bytes[off..^1]
|
||||||
|
GetVal[T](addr seq)
|
||||||
|
|
||||||
|
func WriteVal*[T: not SomeFloat](b: var openArray[byte]; off: uoffset;
|
||||||
|
n: T) {.inline.} =
|
||||||
|
when sizeof(T) == 8:
|
||||||
|
littleEndianX(addr b[off], unsafeAddr n, T.sizeof)
|
||||||
|
elif sizeof(T) == 4:
|
||||||
|
littleEndianX(addr b[off], unsafeAddr n, T.sizeof)
|
||||||
|
elif sizeof(T) == 2:
|
||||||
|
littleEndianX(addr b[off], unsafeAddr n, T.sizeof)
|
||||||
|
elif sizeof(T) == 1:
|
||||||
|
b[off] = n.uint8
|
||||||
|
else:
|
||||||
|
discard
|
||||||
|
#littleEndianX(addr b[off], unsafeAddr n, T.sizeof)
|
||||||
|
#{.error:"shouldnt appear".}
|
||||||
|
|
||||||
|
func WriteVal*[T: not SomeFloat](b: var seq[byte]; off: uoffset;
|
||||||
|
n: T) {.inline.} =
|
||||||
|
when sizeof(T) == 8:
|
||||||
|
littleEndianX(addr b[off], unsafeAddr n, T.sizeof)
|
||||||
|
elif sizeof(T) == 4:
|
||||||
|
littleEndianX(addr b[off], unsafeAddr n, T.sizeof)
|
||||||
|
elif sizeof(T) == 2:
|
||||||
|
littleEndianX(addr b[off], unsafeAddr n, T.sizeof)
|
||||||
|
elif sizeof(T) == 1:
|
||||||
|
b[off] = n.uint8
|
||||||
|
else:
|
||||||
|
discard
|
||||||
|
#littleEndianX(addr b[off], unsafeAddr n, T.sizeof)
|
||||||
|
#{.error:"shouldnt appear".}
|
||||||
|
|
||||||
|
func WriteVal*[T: SomeFloat](b: var openArray[byte]; off: uoffset;
|
||||||
|
n: T) {.inline.} =
|
||||||
|
when T is float64:
|
||||||
|
WriteVal(b, off, cast[uint64](n))
|
||||||
|
elif T is float32:
|
||||||
|
WriteVal(b, off, cast[uint32](n))
|
||||||
|
|
||||||
|
func WriteVal*[T: SomeFloat](b: var seq[byte]; off: uoffset; n: T) {.inline.} =
|
||||||
|
when T is float64:
|
||||||
|
WriteVal(b, off, cast[uint64](n))
|
||||||
|
elif T is float32:
|
||||||
|
WriteVal(b, off, cast[uint32](n))
|
||||||
|
|
||||||
|
func Offset*(this; off: voffset): voffset =
|
||||||
|
let vtable = (this.Pos - this.Get[:uoffset](this.Pos)).voffset
|
||||||
|
let vtableEnd = this.Get[:voffset](vtable)
|
||||||
|
if off < vtableEnd:
|
||||||
|
return this.Get[:voffset](vtable + off)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
func Indirect*(this; off: uoffset): uoffset =
|
||||||
|
result = off + this.Get[:uoffset](off)
|
||||||
|
|
||||||
|
func VectorLen*(this; off: uoffset): int =
|
||||||
|
var newoff: uoffset = off + this.Pos
|
||||||
|
newoff += this.Get[:uoffset](newoff)
|
||||||
|
return this.Get[:uoffset](newoff).int
|
||||||
|
|
||||||
|
func Vector*(this; off: uoffset): uoffset =
|
||||||
|
let newoff: uoffset = off + this.Pos
|
||||||
|
var x: uoffset = newoff + this.Get[:uoffset](newoff)
|
||||||
|
x += (uoffset.sizeof).uoffset
|
||||||
|
result = x
|
||||||
|
|
||||||
|
func Union*(this; off: uoffset): Vtable =
|
||||||
|
let newoff: uoffset = off + this.Pos
|
||||||
|
result.Pos = newoff + this.Get[:uoffset](newoff)
|
||||||
|
result.Bytes = this.Bytes
|
||||||
|
|
||||||
|
func GetSlot*[T](this; slot: voffset; d: T): T =
|
||||||
|
let off = this.Offset(slot)
|
||||||
|
if off == 0:
|
||||||
|
return d
|
||||||
|
return this.Get[T](this.Pos + off)
|
||||||
|
|
||||||
|
func GetOffsetSlot*[T: Offsets](this; slot: voffset; d: T): T =
|
||||||
|
let off = this.Offset(slot)
|
||||||
|
if off == 0:
|
||||||
|
return d
|
||||||
|
return off
|
||||||
|
|
||||||
|
func ByteVector*(this; off: uoffset): seq[byte] =
|
||||||
|
let
|
||||||
|
newoff: uoffset = off + this.Get[:uoffset](off)
|
||||||
|
start = newoff + (uoffset.sizeof).uoffset
|
||||||
|
var newseq = this.Bytes[newoff..^1]
|
||||||
|
let
|
||||||
|
length = GetVal[uoffset](addr newseq)
|
||||||
|
result = this.Bytes[start..<start+length]
|
||||||
|
|
||||||
|
func String*(this; off: uoffset): string =
|
||||||
|
var byte_seq = this.ByteVector(off)
|
||||||
|
result = GetVal[string](addr byte_seq)
|
||||||
|
|
||||||
|
using this: var Vtable
|
||||||
|
|
||||||
|
proc Mutate*[T](this; off: uoffset; n: T): bool =
|
||||||
|
WriteVal(this.Bytes, off, n)
|
||||||
|
return true
|
||||||
|
|
||||||
|
func MutateSlot*[T](this; slot: voffset; n: T): bool =
|
||||||
|
let off: voffset = this.Offset(slot)
|
||||||
|
if off != 0:
|
||||||
|
return this.Mutate(this.Pos + off.uoffset, n)
|
||||||
|
return false
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "flatbuffers",
|
"name": "flatbuffers",
|
||||||
"version": "22.9.29",
|
"version": "22.10.26",
|
||||||
"description": "Memory Efficient Serialization Library",
|
"description": "Memory Efficient Serialization Library",
|
||||||
"files": [
|
"files": [
|
||||||
"js/**/*.js",
|
"js/**/*.js",
|
||||||
|
|||||||
@@ -14,4 +14,4 @@
|
|||||||
|
|
||||||
# Placeholder, to be updated during the release process
|
# Placeholder, to be updated during the release process
|
||||||
# by the setup.py
|
# by the setup.py
|
||||||
__version__ = u"22.9.29"
|
__version__ = u"22.10.26"
|
||||||
|
|||||||
@@ -73,7 +73,32 @@ class EnumVal(object):
|
|||||||
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12))
|
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12))
|
||||||
return o == 0
|
return o == 0
|
||||||
|
|
||||||
def EnumValStart(builder): builder.StartObject(5)
|
# EnumVal
|
||||||
|
def Attributes(self, j):
|
||||||
|
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14))
|
||||||
|
if o != 0:
|
||||||
|
x = self._tab.Vector(o)
|
||||||
|
x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4
|
||||||
|
x = self._tab.Indirect(x)
|
||||||
|
from reflection.KeyValue import KeyValue
|
||||||
|
obj = KeyValue()
|
||||||
|
obj.Init(self._tab.Bytes, x)
|
||||||
|
return obj
|
||||||
|
return None
|
||||||
|
|
||||||
|
# EnumVal
|
||||||
|
def AttributesLength(self):
|
||||||
|
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14))
|
||||||
|
if o != 0:
|
||||||
|
return self._tab.VectorLen(o)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
# EnumVal
|
||||||
|
def AttributesIsNone(self):
|
||||||
|
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14))
|
||||||
|
return o == 0
|
||||||
|
|
||||||
|
def EnumValStart(builder): builder.StartObject(6)
|
||||||
def Start(builder):
|
def Start(builder):
|
||||||
return EnumValStart(builder)
|
return EnumValStart(builder)
|
||||||
def EnumValAddName(builder, name): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0)
|
def EnumValAddName(builder, name): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0)
|
||||||
@@ -91,6 +116,12 @@ def AddDocumentation(builder, documentation):
|
|||||||
def EnumValStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4)
|
def EnumValStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4)
|
||||||
def StartDocumentationVector(builder, numElems):
|
def StartDocumentationVector(builder, numElems):
|
||||||
return EnumValStartDocumentationVector(builder, numElems)
|
return EnumValStartDocumentationVector(builder, numElems)
|
||||||
|
def EnumValAddAttributes(builder, attributes): builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0)
|
||||||
|
def AddAttributes(builder, attributes):
|
||||||
|
return EnumValAddAttributes(builder, attributes)
|
||||||
|
def EnumValStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4)
|
||||||
|
def StartAttributesVector(builder, numElems):
|
||||||
|
return EnumValStartAttributesVector(builder, numElems)
|
||||||
def EnumValEnd(builder): return builder.EndObject()
|
def EnumValEnd(builder): return builder.EndObject()
|
||||||
def End(builder):
|
def End(builder):
|
||||||
return EnumValEnd(builder)
|
return EnumValEnd(builder)
|
||||||
@@ -12,54 +12,14 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import fileinput
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from datetime import datetime
|
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
|
|
||||||
def _update_version_attr(new_version):
|
|
||||||
for line in fileinput.input('flatbuffers/_version.py', inplace=True):
|
|
||||||
if line.startswith('__version__'):
|
|
||||||
line = re.sub(r'".*"', '"{}"'.format(new_version), line)
|
|
||||||
sys.stdout.write(line)
|
|
||||||
|
|
||||||
|
|
||||||
def version():
|
|
||||||
version = os.getenv('VERSION', None)
|
|
||||||
if version:
|
|
||||||
# Most git tags are prefixed with 'v' (example: v1.2.3) this is
|
|
||||||
# never desirable for artifact repositories, so we strip the
|
|
||||||
# leading 'v' if it's present.
|
|
||||||
version = version[1:] if version.startswith('v') else version
|
|
||||||
else:
|
|
||||||
# Default version is an ISO8601 compiliant datetime. PyPI doesn't allow
|
|
||||||
# the colon ':' character in its versions, and time is required to allow
|
|
||||||
# for multiple publications to master in one day. This datetime string
|
|
||||||
# uses the "basic" ISO8601 format for both its date and time components
|
|
||||||
# to avoid issues with the colon character (ISO requires that date and
|
|
||||||
# time components of a date-time string must be uniformly basic or
|
|
||||||
# extended, which is why the date component does not have dashes.
|
|
||||||
#
|
|
||||||
# Publications using datetime versions should only be made from master
|
|
||||||
# to represent the HEAD moving forward.
|
|
||||||
version = datetime.utcnow().strftime('%Y%m%d%H%M%S')
|
|
||||||
print("VERSION environment variable not set, using datetime instead: {}"
|
|
||||||
.format(version))
|
|
||||||
|
|
||||||
_update_version_attr(version)
|
|
||||||
|
|
||||||
return version
|
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='flatbuffers',
|
name='flatbuffers',
|
||||||
version=version(),
|
version='22.10.26',
|
||||||
license='Apache 2.0',
|
license='Apache 2.0',
|
||||||
author='FlatBuffers Contributors',
|
author='Derek Bailey',
|
||||||
author_email='me@rwinslow.com',
|
author_email='derekbailey@google.com',
|
||||||
url='https://google.github.io/flatbuffers/',
|
url='https://google.github.io/flatbuffers/',
|
||||||
long_description=('Python runtime library for use with the '
|
long_description=('Python runtime library for use with the '
|
||||||
'`Flatbuffers <https://google.github.io/flatbuffers/>`_ '
|
'`Flatbuffers <https://google.github.io/flatbuffers/>`_ '
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ table EnumVal {
|
|||||||
object:Object (deprecated);
|
object:Object (deprecated);
|
||||||
union_type:Type;
|
union_type:Type;
|
||||||
documentation:[string];
|
documentation:[string];
|
||||||
|
attributes:[KeyValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
table Enum {
|
table Enum {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "flatbuffers"
|
name = "flatbuffers"
|
||||||
version = "2.1.2"
|
version = "22.9.29"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
authors = ["Robert Winslow <hello@rwinslow.com>", "FlatBuffers Maintainers"]
|
authors = ["Robert Winslow <hello@rwinslow.com>", "FlatBuffers Maintainers"]
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
@@ -12,14 +12,13 @@ categories = ["encoding", "data-structures", "memory-management"]
|
|||||||
rust = "1.51"
|
rust = "1.51"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["thiserror"]
|
default = ["std"]
|
||||||
no_std = ["core2", "thiserror_core2"]
|
std = []
|
||||||
serialize = ["serde"]
|
serialize = ["serde"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1.2.1"
|
bitflags = "1.2.1"
|
||||||
serde = { version = "1.0", optional = true }
|
serde = { version = "1.0", optional = true }
|
||||||
thiserror = { version = "1.0.30", optional = true }
|
|
||||||
core2 = { version = "0.4.0", optional = true }
|
[build-dependencies]
|
||||||
# This version is compliant with mainline 1.0.30
|
rustc_version = "0.4.0"
|
||||||
thiserror_core2 = { version = "2.0.0", default-features = false, optional = true }
|
|
||||||
|
|||||||
12
rust/flatbuffers/build.rs
Normal file
12
rust/flatbuffers/build.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
use rustc_version::{version_meta, Channel};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let version_meta = version_meta().unwrap();
|
||||||
|
|
||||||
|
// To use nightly features we declare this and then we can use
|
||||||
|
// #[cfg(nightly)]
|
||||||
|
// for nightly only features
|
||||||
|
if version_meta.channel == Channel::Nightly {
|
||||||
|
println!("cargo:rustc-cfg=nightly")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(not(feature = "std"))]
|
||||||
use alloc::{vec, vec::Vec};
|
use alloc::{vec, vec::Vec};
|
||||||
use core::cmp::max;
|
use core::cmp::max;
|
||||||
use core::iter::{DoubleEndedIterator, ExactSizeIterator};
|
use core::iter::{DoubleEndedIterator, ExactSizeIterator};
|
||||||
@@ -116,7 +116,7 @@ impl<'fbb> FlatBufferBuilder<'fbb> {
|
|||||||
// memset only the part of the buffer that could be dirty:
|
// memset only the part of the buffer that could be dirty:
|
||||||
{
|
{
|
||||||
let to_clear = self.owned_buf.len() - self.head;
|
let to_clear = self.owned_buf.len() - self.head;
|
||||||
let ptr = (&mut self.owned_buf[self.head..]).as_mut_ptr();
|
let ptr = self.owned_buf[self.head..].as_mut_ptr();
|
||||||
// Safety:
|
// Safety:
|
||||||
// Verified ptr is valid for `to_clear` above
|
// Verified ptr is valid for `to_clear` above
|
||||||
unsafe {
|
unsafe {
|
||||||
@@ -150,7 +150,7 @@ impl<'fbb> FlatBufferBuilder<'fbb> {
|
|||||||
self.align(sz, P::alignment());
|
self.align(sz, P::alignment());
|
||||||
self.make_space(sz);
|
self.make_space(sz);
|
||||||
{
|
{
|
||||||
let (dst, rest) = (&mut self.owned_buf[self.head..]).split_at_mut(sz);
|
let (dst, rest) = self.owned_buf[self.head..].split_at_mut(sz);
|
||||||
// Safety:
|
// Safety:
|
||||||
// Called make_space above
|
// Called make_space above
|
||||||
unsafe { x.push(dst, rest.len()) };
|
unsafe { x.push(dst, rest.len()) };
|
||||||
@@ -605,7 +605,7 @@ impl<'fbb> FlatBufferBuilder<'fbb> {
|
|||||||
}
|
}
|
||||||
// finally, zero out the old end data.
|
// finally, zero out the old end data.
|
||||||
{
|
{
|
||||||
let ptr = (&mut self.owned_buf[..middle]).as_mut_ptr();
|
let ptr = self.owned_buf[..middle].as_mut_ptr();
|
||||||
// Safety:
|
// Safety:
|
||||||
// ptr is byte aligned and of length middle
|
// ptr is byte aligned and of length middle
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|||||||
@@ -179,10 +179,6 @@ pub unsafe fn read_scalar<T: EndianScalar>(s: &[u8]) -> T {
|
|||||||
|
|
||||||
let mut mem = core::mem::MaybeUninit::<T::Scalar>::uninit();
|
let mut mem = core::mem::MaybeUninit::<T::Scalar>::uninit();
|
||||||
// Since [u8] has alignment 1, we copy it into T which may have higher alignment.
|
// Since [u8] has alignment 1, we copy it into T which may have higher alignment.
|
||||||
core::ptr::copy_nonoverlapping(
|
core::ptr::copy_nonoverlapping(s.as_ptr(), mem.as_mut_ptr() as *mut u8, size);
|
||||||
s.as_ptr(),
|
|
||||||
mem.as_mut_ptr() as *mut u8,
|
|
||||||
size,
|
|
||||||
);
|
|
||||||
T::from_little_endian(mem.assume_init())
|
T::from_little_endian(mem.assume_init())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,9 +28,10 @@
|
|||||||
//! At this time, to generate Rust code, you will need the latest `master` version of `flatc`, available from here: <https://github.com/google/flatbuffers>
|
//! At this time, to generate Rust code, you will need the latest `master` version of `flatc`, available from here: <https://github.com/google/flatbuffers>
|
||||||
//! (On OSX, you can install FlatBuffers from `HEAD` with the Homebrew package manager.)
|
//! (On OSX, you can install FlatBuffers from `HEAD` with the Homebrew package manager.)
|
||||||
|
|
||||||
#![cfg_attr(feature = "no_std", no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
#![cfg_attr(all(nightly, not(feature = "std")), feature(error_in_core))]
|
||||||
|
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(not(feature = "std"))]
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
mod array;
|
mod array;
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
use crate::follow::Follow;
|
use crate::follow::Follow;
|
||||||
use crate::{ForwardsUOffset, SOffsetT, SkipSizePrefix, UOffsetT, VOffsetT, Vector, SIZE_UOFFSET};
|
use crate::{ForwardsUOffset, SOffsetT, SkipSizePrefix, UOffsetT, VOffsetT, Vector, SIZE_UOFFSET};
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(not(feature = "std"))]
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use core::ops::Range;
|
use core::ops::Range;
|
||||||
use core::option::Option;
|
use core::option::Option;
|
||||||
|
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(all(nightly, not(feature = "std")))]
|
||||||
use thiserror::Error;
|
use core::error::Error;
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "std")]
|
||||||
use thiserror_core2::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
/// Traces the location of data errors. Not populated for Dos detecting errors.
|
/// Traces the location of data errors. Not populated for Dos detecting errors.
|
||||||
/// Useful for MissingRequiredField and Utf8Error in particular, though
|
/// Useful for MissingRequiredField and Utf8Error in particular, though
|
||||||
@@ -41,64 +41,138 @@ impl core::convert::AsRef<[ErrorTraceDetail]> for ErrorTrace {
|
|||||||
|
|
||||||
/// Describes how a flatuffer is invalid and, for data errors, roughly where. No extra tracing
|
/// Describes how a flatuffer is invalid and, for data errors, roughly where. No extra tracing
|
||||||
/// information is given for DoS detecting errors since it will probably be a lot.
|
/// information is given for DoS detecting errors since it will probably be a lot.
|
||||||
#[derive(Clone, Error, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum InvalidFlatbuffer {
|
pub enum InvalidFlatbuffer {
|
||||||
#[error("Missing required field `{required}`.\n{error_trace}")]
|
|
||||||
MissingRequiredField {
|
MissingRequiredField {
|
||||||
required: &'static str,
|
required: &'static str,
|
||||||
error_trace: ErrorTrace,
|
error_trace: ErrorTrace,
|
||||||
},
|
},
|
||||||
#[error(
|
|
||||||
"Union exactly one of union discriminant (`{field_type}`) and value \
|
|
||||||
(`{field}`) are present.\n{error_trace}"
|
|
||||||
)]
|
|
||||||
InconsistentUnion {
|
InconsistentUnion {
|
||||||
field: &'static str,
|
field: &'static str,
|
||||||
field_type: &'static str,
|
field_type: &'static str,
|
||||||
error_trace: ErrorTrace,
|
error_trace: ErrorTrace,
|
||||||
},
|
},
|
||||||
#[error("Utf8 error for string in {range:?}: {error}\n{error_trace}")]
|
|
||||||
Utf8Error {
|
Utf8Error {
|
||||||
#[source]
|
|
||||||
error: core::str::Utf8Error,
|
error: core::str::Utf8Error,
|
||||||
range: Range<usize>,
|
range: Range<usize>,
|
||||||
error_trace: ErrorTrace,
|
error_trace: ErrorTrace,
|
||||||
},
|
},
|
||||||
#[error("String in range [{}, {}) is missing its null terminator.\n{error_trace}",
|
|
||||||
range.start, range.end)]
|
|
||||||
MissingNullTerminator {
|
MissingNullTerminator {
|
||||||
range: Range<usize>,
|
range: Range<usize>,
|
||||||
error_trace: ErrorTrace,
|
error_trace: ErrorTrace,
|
||||||
},
|
},
|
||||||
#[error("Type `{unaligned_type}` at position {position} is unaligned.\n{error_trace}")]
|
|
||||||
Unaligned {
|
Unaligned {
|
||||||
position: usize,
|
position: usize,
|
||||||
unaligned_type: &'static str,
|
unaligned_type: &'static str,
|
||||||
error_trace: ErrorTrace,
|
error_trace: ErrorTrace,
|
||||||
},
|
},
|
||||||
#[error("Range [{}, {}) is out of bounds.\n{error_trace}", range.start, range.end)]
|
|
||||||
RangeOutOfBounds {
|
RangeOutOfBounds {
|
||||||
range: Range<usize>,
|
range: Range<usize>,
|
||||||
error_trace: ErrorTrace,
|
error_trace: ErrorTrace,
|
||||||
},
|
},
|
||||||
#[error(
|
|
||||||
"Signed offset at position {position} has value {soffset} which points out of bounds.\
|
|
||||||
\n{error_trace}"
|
|
||||||
)]
|
|
||||||
SignedOffsetOutOfBounds {
|
SignedOffsetOutOfBounds {
|
||||||
soffset: SOffsetT,
|
soffset: SOffsetT,
|
||||||
position: usize,
|
position: usize,
|
||||||
error_trace: ErrorTrace,
|
error_trace: ErrorTrace,
|
||||||
},
|
},
|
||||||
// Dos detecting errors. These do not get error traces since it will probably be very large.
|
// Dos detecting errors. These do not get error traces since it will probably be very large.
|
||||||
#[error("Too many tables.")]
|
|
||||||
TooManyTables,
|
TooManyTables,
|
||||||
#[error("Apparent size too large.")]
|
|
||||||
ApparentSizeTooLarge,
|
ApparentSizeTooLarge,
|
||||||
#[error("Nested table depth limit reached.")]
|
|
||||||
DepthLimitReached,
|
DepthLimitReached,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(nightly, feature = "std"))]
|
||||||
|
impl Error for InvalidFlatbuffer {
|
||||||
|
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||||
|
if let InvalidFlatbuffer::Utf8Error { error: source, .. } = self {
|
||||||
|
Some(source)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl core::fmt::Display for InvalidFlatbuffer {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||||
|
match self {
|
||||||
|
InvalidFlatbuffer::MissingRequiredField {
|
||||||
|
required,
|
||||||
|
error_trace,
|
||||||
|
} => {
|
||||||
|
writeln!(f, "Missing required field `{}`.\n{}", required, error_trace)?;
|
||||||
|
}
|
||||||
|
InvalidFlatbuffer::InconsistentUnion {
|
||||||
|
field,
|
||||||
|
field_type,
|
||||||
|
error_trace,
|
||||||
|
} => {
|
||||||
|
writeln!(
|
||||||
|
f,
|
||||||
|
"Exactly one of union discriminant (`{}`) and value (`{}`) are present.\n{}",
|
||||||
|
field_type, field, error_trace
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
InvalidFlatbuffer::Utf8Error {
|
||||||
|
error,
|
||||||
|
range,
|
||||||
|
error_trace,
|
||||||
|
} => {
|
||||||
|
writeln!(
|
||||||
|
f,
|
||||||
|
"Utf8 error for string in {:?}: {}\n{}",
|
||||||
|
range, error, error_trace
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
InvalidFlatbuffer::MissingNullTerminator { range, error_trace } => {
|
||||||
|
writeln!(
|
||||||
|
f,
|
||||||
|
"String in range [{}, {}) is missing its null terminator.\n{}",
|
||||||
|
range.start, range.end, error_trace
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
InvalidFlatbuffer::Unaligned {
|
||||||
|
position,
|
||||||
|
unaligned_type,
|
||||||
|
error_trace,
|
||||||
|
} => {
|
||||||
|
writeln!(
|
||||||
|
f,
|
||||||
|
"Type `{}` at position {} is unaligned.\n{}",
|
||||||
|
unaligned_type, position, error_trace
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
InvalidFlatbuffer::RangeOutOfBounds { range, error_trace } => {
|
||||||
|
writeln!(
|
||||||
|
f,
|
||||||
|
"Range [{}, {}) is out of bounds.\n{}",
|
||||||
|
range.start, range.end, error_trace
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
InvalidFlatbuffer::SignedOffsetOutOfBounds {
|
||||||
|
soffset,
|
||||||
|
position,
|
||||||
|
error_trace,
|
||||||
|
} => {
|
||||||
|
writeln!(
|
||||||
|
f,
|
||||||
|
"Signed offset at position {} has value {} which points out of bounds.\n{}",
|
||||||
|
position, soffset, error_trace
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
InvalidFlatbuffer::TooManyTables {} => {
|
||||||
|
writeln!(f, "Too many tables.")?;
|
||||||
|
}
|
||||||
|
InvalidFlatbuffer::ApparentSizeTooLarge {} => {
|
||||||
|
writeln!(f, "Apparent size too large.")?;
|
||||||
|
}
|
||||||
|
InvalidFlatbuffer::DepthLimitReached {} => {
|
||||||
|
writeln!(f, "Nested table depth limit reached.")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl core::fmt::Display for ErrorTrace {
|
impl core::fmt::Display for ErrorTrace {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||||
use ErrorTraceDetail::*;
|
use ErrorTraceDetail::*;
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ impl<'de> Buffer for &'de [u8] {
|
|||||||
/// Based off of the `empty` function, allows override for optimization purposes.
|
/// Based off of the `empty` function, allows override for optimization purposes.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn empty_str() -> Self::BufferString {
|
fn empty_str() -> Self::BufferString {
|
||||||
&""
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ impl<'a> MapBuilder<'a> {
|
|||||||
// Nested vector.
|
// Nested vector.
|
||||||
let start = Some(self.builder.values.len());
|
let start = Some(self.builder.values.len());
|
||||||
VectorBuilder {
|
VectorBuilder {
|
||||||
builder: &mut self.builder,
|
builder: self.builder,
|
||||||
start,
|
start,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ impl<'a> MapBuilder<'a> {
|
|||||||
// Nested map.
|
// Nested map.
|
||||||
let start = Some(self.builder.values.len());
|
let start = Some(self.builder.values.len());
|
||||||
MapBuilder {
|
MapBuilder {
|
||||||
builder: &mut self.builder,
|
builder: self.builder,
|
||||||
start,
|
start,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ impl ser::Error for Error {
|
|||||||
Self::Serde(format!("{}", msg))
|
Self::Serde(format!("{}", msg))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'a> ser::SerializeSeq for &mut FlexbufferSerializer {
|
impl ser::SerializeSeq for &mut FlexbufferSerializer {
|
||||||
type Ok = ();
|
type Ok = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||||
@@ -113,14 +113,14 @@ impl<'a> ser::SerializeSeq for &mut FlexbufferSerializer {
|
|||||||
}
|
}
|
||||||
// This is unlike a flexbuffers map which requires CString like keys.
|
// This is unlike a flexbuffers map which requires CString like keys.
|
||||||
// Its implemented as alternating keys and values (hopefully).
|
// Its implemented as alternating keys and values (hopefully).
|
||||||
impl<'a> ser::SerializeMap for &'a mut FlexbufferSerializer {
|
impl ser::SerializeMap for &mut FlexbufferSerializer {
|
||||||
type Ok = ();
|
type Ok = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Self::Error>
|
fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Self::Error>
|
||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
key.serialize(MapKeySerializer(&mut **self))
|
key.serialize(MapKeySerializer(self))
|
||||||
}
|
}
|
||||||
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||||
where
|
where
|
||||||
@@ -132,7 +132,7 @@ impl<'a> ser::SerializeMap for &'a mut FlexbufferSerializer {
|
|||||||
self.end_map()
|
self.end_map()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'a> ser::SerializeTuple for &mut FlexbufferSerializer {
|
impl ser::SerializeTuple for &mut FlexbufferSerializer {
|
||||||
type Ok = ();
|
type Ok = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||||
@@ -145,7 +145,7 @@ impl<'a> ser::SerializeTuple for &mut FlexbufferSerializer {
|
|||||||
self.end_vector()
|
self.end_vector()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'a> ser::SerializeTupleStruct for &mut FlexbufferSerializer {
|
impl ser::SerializeTupleStruct for &mut FlexbufferSerializer {
|
||||||
type Ok = ();
|
type Ok = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||||
@@ -158,7 +158,7 @@ impl<'a> ser::SerializeTupleStruct for &mut FlexbufferSerializer {
|
|||||||
self.end_vector()
|
self.end_vector()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'a> ser::SerializeStruct for &mut FlexbufferSerializer {
|
impl ser::SerializeStruct for &mut FlexbufferSerializer {
|
||||||
type Ok = ();
|
type Ok = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
fn serialize_field<T: ?Sized>(
|
fn serialize_field<T: ?Sized>(
|
||||||
@@ -176,7 +176,7 @@ impl<'a> ser::SerializeStruct for &mut FlexbufferSerializer {
|
|||||||
self.end_map()
|
self.end_map()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'a> ser::SerializeTupleVariant for &mut FlexbufferSerializer {
|
impl ser::SerializeTupleVariant for &mut FlexbufferSerializer {
|
||||||
type Ok = ();
|
type Ok = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||||
@@ -190,7 +190,7 @@ impl<'a> ser::SerializeTupleVariant for &mut FlexbufferSerializer {
|
|||||||
self.end_map()
|
self.end_map()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'a> ser::SerializeStructVariant for &mut FlexbufferSerializer {
|
impl ser::SerializeStructVariant for &mut FlexbufferSerializer {
|
||||||
type Ok = ();
|
type Ok = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
fn serialize_field<T: ?Sized>(
|
fn serialize_field<T: ?Sized>(
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ impl<'a> VectorBuilder<'a> {
|
|||||||
pub fn start_vector(&mut self) -> VectorBuilder {
|
pub fn start_vector(&mut self) -> VectorBuilder {
|
||||||
let start = Some(self.builder.values.len());
|
let start = Some(self.builder.values.len());
|
||||||
VectorBuilder {
|
VectorBuilder {
|
||||||
builder: &mut self.builder,
|
builder: self.builder,
|
||||||
start,
|
start,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ impl<'a> VectorBuilder<'a> {
|
|||||||
pub fn start_map(&mut self) -> MapBuilder {
|
pub fn start_map(&mut self) -> MapBuilder {
|
||||||
let start = Some(self.builder.values.len());
|
let start = Some(self.builder.values.len());
|
||||||
MapBuilder {
|
MapBuilder {
|
||||||
builder: &mut self.builder,
|
builder: self.builder,
|
||||||
start,
|
start,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
// Serde with maps - field names and type names.
|
// Serde with maps - field names and type names.
|
||||||
|
|
||||||
// Until flat/flexbuffers is on Rust v1.42, we cannot use the previously unstable matches! macro.
|
// Until flat/flexbuffers is on Rust v1.42, we cannot use the previously unstable matches! macro.
|
||||||
#![allow(clippy::unknown_clippy_lints)]
|
#![allow(unknown_lints)]
|
||||||
#![allow(clippy::match_like_matches_macro)]
|
#![allow(clippy::match_like_matches_macro)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|||||||
@@ -380,7 +380,7 @@ impl<B: Buffer> Reader<B> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_blob(&self) -> Blob<B> {
|
pub fn as_blob(&self) -> Blob<B> {
|
||||||
self.get_blob().unwrap_or(Blob(B::empty()))
|
self.get_blob().unwrap_or_else(|_| Blob(B::empty()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves str pointer, errors if invalid UTF-8, or the provided index
|
/// Retrieves str pointer, errors if invalid UTF-8, or the provided index
|
||||||
@@ -580,8 +580,8 @@ impl<B: Buffer> Reader<B> {
|
|||||||
/// Returns empty string if you're not trying to read a string.
|
/// Returns empty string if you're not trying to read a string.
|
||||||
pub fn as_str(&self) -> B::BufferString {
|
pub fn as_str(&self) -> B::BufferString {
|
||||||
match self.fxb_type {
|
match self.fxb_type {
|
||||||
FlexBufferType::String => self.get_str().unwrap_or(B::empty_str()),
|
FlexBufferType::String => self.get_str().unwrap_or_else(|_| B::empty_str()),
|
||||||
FlexBufferType::Key => self.get_key().unwrap_or(B::empty_str()),
|
FlexBufferType::Key => self.get_key().unwrap_or_else(|_| B::empty_str()),
|
||||||
_ => B::empty_str(),
|
_ => B::empty_str(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -9,8 +9,8 @@
|
|||||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||||
// generated, otherwise it may not be compatible.
|
// generated, otherwise it may not be compatible.
|
||||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 22 &&
|
static_assert(FLATBUFFERS_VERSION_MAJOR == 22 &&
|
||||||
FLATBUFFERS_VERSION_MINOR == 9 &&
|
FLATBUFFERS_VERSION_MINOR == 10 &&
|
||||||
FLATBUFFERS_VERSION_REVISION == 29,
|
FLATBUFFERS_VERSION_REVISION == 26,
|
||||||
"Non-compatible flatbuffers version included");
|
"Non-compatible flatbuffers version included");
|
||||||
|
|
||||||
namespace MyGame {
|
namespace MyGame {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public enum MyGame_Sample_Equipment: UInt8, Enum {
|
|||||||
|
|
||||||
public struct MyGame_Sample_Vec3: NativeStruct {
|
public struct MyGame_Sample_Vec3: NativeStruct {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_22_9_29() }
|
static func validateVersion() { FlatBuffersVersion_22_10_26() }
|
||||||
|
|
||||||
private var _x: Float32
|
private var _x: Float32
|
||||||
private var _y: Float32
|
private var _y: Float32
|
||||||
@@ -56,7 +56,7 @@ public struct MyGame_Sample_Vec3: NativeStruct {
|
|||||||
|
|
||||||
public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
|
public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_22_9_29() }
|
static func validateVersion() { FlatBuffersVersion_22_10_26() }
|
||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Struct
|
private var _accessor: Struct
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
|
|||||||
|
|
||||||
public struct MyGame_Sample_Monster: FlatBufferObject {
|
public struct MyGame_Sample_Monster: FlatBufferObject {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_22_9_29() }
|
static func validateVersion() { FlatBuffersVersion_22_10_26() }
|
||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ public struct MyGame_Sample_Monster: FlatBufferObject {
|
|||||||
|
|
||||||
public struct MyGame_Sample_Weapon: FlatBufferObject {
|
public struct MyGame_Sample_Weapon: FlatBufferObject {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_22_9_29() }
|
static func validateVersion() { FlatBuffersVersion_22_10_26() }
|
||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ extern crate flatbuffers;
|
|||||||
|
|
||||||
// import the generated code
|
// import the generated code
|
||||||
#[allow(dead_code, unused_imports)]
|
#[allow(dead_code, unused_imports)]
|
||||||
#[allow(clippy::approx_constant)] // We use low precision PI as a default value.
|
#[allow(clippy::all)]
|
||||||
mod rust_generated;
|
mod rust_generated;
|
||||||
pub use rust_generated::my_game::sample::{Color, Equipment,
|
pub use rust_generated::my_game::sample::{Color, Equipment,
|
||||||
Monster, MonsterArgs,
|
Monster, MonsterArgs,
|
||||||
|
|||||||
@@ -371,6 +371,12 @@ flatc(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
flatc(
|
||||||
|
BASE_OPTS + PYTHON_OPTS,
|
||||||
|
schema="nested_union_test.fbs",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Optional Scalars
|
# Optional Scalars
|
||||||
optional_scalars_schema = "optional_scalars.fbs"
|
optional_scalars_schema = "optional_scalars.fbs"
|
||||||
flatc(["--java", "--kotlin", "--lobster"], schema=optional_scalars_schema)
|
flatc(["--java", "--kotlin", "--lobster"], schema=optional_scalars_schema)
|
||||||
@@ -449,6 +455,13 @@ flatc(
|
|||||||
cwd=swift_code_gen
|
cwd=swift_code_gen
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Nim Tests
|
||||||
|
NIM_OPTS = BASE_OPTS + ["--nim"]
|
||||||
|
flatc(NIM_OPTS, schema="monster_test.fbs", include="include_test")
|
||||||
|
flatc(NIM_OPTS, schema="optional_scalars.fbs")
|
||||||
|
flatc(NIM_OPTS, schema="more_defaults.fbs")
|
||||||
|
flatc(NIM_OPTS, schema="MutatingBool.fbs")
|
||||||
|
|
||||||
# --filename-suffix and --filename-ext tests
|
# --filename-suffix and --filename-ext tests
|
||||||
flatc(
|
flatc(
|
||||||
CPP_OPTS + NO_INCL_OPTS + ["--grpc", "--filename-ext", "hpp"],
|
CPP_OPTS + NO_INCL_OPTS + ["--grpc", "--filename-ext", "hpp"],
|
||||||
|
|||||||
81
scripts/release.sh
Executable file
81
scripts/release.sh
Executable file
@@ -0,0 +1,81 @@
|
|||||||
|
|
||||||
|
printf -v year '%(%y)T' -1
|
||||||
|
printf -v month '%(%m)T' -1
|
||||||
|
printf -v day '%(%d)T' -1
|
||||||
|
|
||||||
|
version="$year.$month.$day"
|
||||||
|
version_underscore="$year\_$month\_$day"
|
||||||
|
|
||||||
|
echo "Setting Flatbuffers Version to: $version"
|
||||||
|
|
||||||
|
echo "Updating include/flatbuffers/base.h..."
|
||||||
|
sed -i \
|
||||||
|
-e "s/\(#define FLATBUFFERS_VERSION_MAJOR \).*/\1$year/" \
|
||||||
|
-e "s/\(#define FLATBUFFERS_VERSION_MINOR \).*/\1$month/" \
|
||||||
|
-e "s/\(#define FLATBUFFERS_VERSION_REVISION \).*/\1$day/" \
|
||||||
|
include/flatbuffers/base.h
|
||||||
|
|
||||||
|
echo "Updating CMake\Version.cmake..."
|
||||||
|
sed -i \
|
||||||
|
-e "s/\(set(VERSION_MAJOR \).*/\1$year)/" \
|
||||||
|
-e "s/\(set(VERSION_MINOR \).*/\1$month)/" \
|
||||||
|
-e "s/\(set(VERSION_PATCH \).*/\1$day)/" \
|
||||||
|
CMake/Version.cmake
|
||||||
|
|
||||||
|
echo "Updating include/flatbuffers/reflection_generated.h..."
|
||||||
|
echo "Updating tests/evolution_test/evolution_v1_generated.h..."
|
||||||
|
echo "Updating tests/evolution_test/evolution_v1_generated.h..."
|
||||||
|
sed -i \
|
||||||
|
-e "s/\(FLATBUFFERS_VERSION_MAJOR == \)[0-9]*\(.*\)/\1$year\2/" \
|
||||||
|
-e "s/\(FLATBUFFERS_VERSION_MINOR == \)[0-9]*\(.*\)/\1$month\2/" \
|
||||||
|
-e "s/\(FLATBUFFERS_VERSION_REVISION == \)[0-9]*\(.*\)/\1$day\2/" \
|
||||||
|
include/flatbuffers/reflection_generated.h \
|
||||||
|
tests/evolution_test/evolution_v1_generated.h \
|
||||||
|
tests/evolution_test/evolution_v2_generated.h
|
||||||
|
|
||||||
|
echo "Updating java/pom.xml..."
|
||||||
|
xmlstarlet edit --inplace -N s=http://maven.apache.org/POM/4.0.0 \
|
||||||
|
--update '//s:project/s:version' --value $version \
|
||||||
|
java/pom.xml
|
||||||
|
|
||||||
|
echo "Updating package.json..."
|
||||||
|
sed -i \
|
||||||
|
-e "s/\(\"version\": \).*/\1\"$version\",/" \
|
||||||
|
package.json
|
||||||
|
|
||||||
|
echo "Updating net/FlatBuffers/Google.FlatBuffers.csproj..."
|
||||||
|
sed -i \
|
||||||
|
-e "s/\(<PackageVersion>\).*\(<\/PackageVersion>\)/\1$version\2/" \
|
||||||
|
net/FlatBuffers/Google.FlatBuffers.csproj
|
||||||
|
|
||||||
|
echo "Updating dart/pubspec.yaml..."
|
||||||
|
sed -i \
|
||||||
|
-e "s/\(version: \).*/\1$version/" \
|
||||||
|
dart/pubspec.yaml
|
||||||
|
|
||||||
|
echo "Updating python/flatbuffers/_version.py..."
|
||||||
|
sed -i \
|
||||||
|
-e "s/\(__version__ = u\).*/\1\"$version\"/" \
|
||||||
|
python/flatbuffers/_version.py
|
||||||
|
|
||||||
|
echo "Updating python/setup.py..."
|
||||||
|
sed -i \
|
||||||
|
-e "s/\(version='\).*/\1$version',/" \
|
||||||
|
python/setup.py
|
||||||
|
|
||||||
|
echo "Updating FlatBuffers.podspec..."
|
||||||
|
sed -i \
|
||||||
|
-e "s/\(s.version\s*= \).*/\1'$version'/" \
|
||||||
|
FlatBuffers.podspec
|
||||||
|
|
||||||
|
echo "Updating FlatBuffersVersion_X_X_X() version check...."
|
||||||
|
grep -rl 'FlatBuffersVersion_' * --exclude=release.sh | xargs -i@ \
|
||||||
|
sed -i \
|
||||||
|
-e "s/\(FlatBuffersVersion_\).*()/\1$version_underscore()/g" \
|
||||||
|
@
|
||||||
|
|
||||||
|
echo "Updating FLATBUFFERS_X_X_X() version check...."
|
||||||
|
grep -rl 'FLATBUFFERS_\d*' * --exclude=release.sh | xargs -i@ \
|
||||||
|
sed -i \
|
||||||
|
-e "s/\(FLATBUFFERS_\)[0-9]\{2\}.*()/\1$version_underscore()/g" \
|
||||||
|
@
|
||||||
@@ -39,6 +39,8 @@ cc_library(
|
|||||||
"bfbs_gen.h",
|
"bfbs_gen.h",
|
||||||
"bfbs_gen_lua.cpp",
|
"bfbs_gen_lua.cpp",
|
||||||
"bfbs_gen_lua.h",
|
"bfbs_gen_lua.h",
|
||||||
|
"bfbs_gen_nim.cpp",
|
||||||
|
"bfbs_gen_nim.h",
|
||||||
"bfbs_namer.h",
|
"bfbs_namer.h",
|
||||||
"binary_annotator.cpp",
|
"binary_annotator.cpp",
|
||||||
"binary_annotator.h",
|
"binary_annotator.h",
|
||||||
@@ -62,6 +64,8 @@ cc_library(
|
|||||||
"bfbs_gen.h",
|
"bfbs_gen.h",
|
||||||
"bfbs_gen_lua.cpp",
|
"bfbs_gen_lua.cpp",
|
||||||
"bfbs_gen_lua.h",
|
"bfbs_gen_lua.h",
|
||||||
|
"bfbs_gen_nim.cpp",
|
||||||
|
"bfbs_gen_nim.h",
|
||||||
"bfbs_namer.h",
|
"bfbs_namer.h",
|
||||||
"flatc_main.cpp",
|
"flatc_main.cpp",
|
||||||
"idl_gen_cpp.cpp",
|
"idl_gen_cpp.cpp",
|
||||||
|
|||||||
@@ -38,8 +38,9 @@ static void ForAllObjects(
|
|||||||
for (auto it = objects->cbegin(); it != objects->cend(); ++it) { func(*it); }
|
for (auto it = objects->cbegin(); it != objects->cend(); ++it) { func(*it); }
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ForAllEnumValues(const reflection::Enum *enum_def,
|
static void ForAllEnumValues(
|
||||||
std::function<void(const reflection::EnumVal *)> func) {
|
const reflection::Enum *enum_def,
|
||||||
|
std::function<void(const reflection::EnumVal *)> func) {
|
||||||
for (auto it = enum_def->values()->cbegin(); it != enum_def->values()->cend();
|
for (auto it = enum_def->values()->cbegin(); it != enum_def->values()->cend();
|
||||||
++it) {
|
++it) {
|
||||||
func(*it);
|
func(*it);
|
||||||
@@ -91,7 +92,7 @@ static bool IsVector(const reflection::BaseType base_type) {
|
|||||||
return base_type == reflection::Vector;
|
return base_type == reflection::Vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// A concrete base Flatbuffer Generator that specific language generators can
|
// A concrete base Flatbuffer Generator that specific language generators can
|
||||||
// derive from.
|
// derive from.
|
||||||
@@ -130,17 +131,29 @@ class BaseBfbsGenerator : public BfbsGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const reflection::Object *GetObject(const reflection::Type *type) const {
|
// GetObject returns the underlying object struct of the given type
|
||||||
if (type->index() >= 0 && IsStructOrTable(type->base_type())) {
|
// if element_type is true and GetObject is a list of objects then
|
||||||
|
// GetObject will correctly return the object struct of the vector's elements
|
||||||
|
const reflection::Object *GetObject(const reflection::Type *type,
|
||||||
|
bool element_type = false) const {
|
||||||
|
const reflection::BaseType base_type =
|
||||||
|
element_type ? type->element() : type->base_type();
|
||||||
|
if (type->index() >= 0 && IsStructOrTable(base_type)) {
|
||||||
return GetObjectByIndex(type->index());
|
return GetObjectByIndex(type->index());
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const reflection::Enum *GetEnum(const reflection::Type *type) const {
|
// GetEnum returns the underlying enum struct of the given type
|
||||||
|
// if element_type is true and GetEnum is a list of enums then
|
||||||
|
// GetEnum will correctly return the enum struct of the vector's elements
|
||||||
|
const reflection::Enum *GetEnum(const reflection::Type *type,
|
||||||
|
bool element_type = false) const {
|
||||||
|
const reflection::BaseType base_type =
|
||||||
|
element_type ? type->element() : type->base_type();
|
||||||
// TODO(derekbailey): it would be better to have a explicit list of allowed
|
// TODO(derekbailey): it would be better to have a explicit list of allowed
|
||||||
// base types, instead of negating Obj types.
|
// base types, instead of negating Obj types.
|
||||||
if (type->index() >= 0 && !IsStructOrTable(type->base_type())) {
|
if (type->index() >= 0 && !IsStructOrTable(base_type)) {
|
||||||
return GetEnumByIndex(type->index());
|
return GetEnumByIndex(type->index());
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ class LuaBfbsGenerator : public BaseBfbsGenerator {
|
|||||||
// Skip writing deprecated fields altogether.
|
// Skip writing deprecated fields altogether.
|
||||||
if (field->deprecated()) { return; }
|
if (field->deprecated()) { return; }
|
||||||
|
|
||||||
const std::string field_name = namer_.Field(field->name()->str());
|
const std::string field_name = namer_.Field(*field);
|
||||||
const r::BaseType base_type = field->type()->base_type();
|
const r::BaseType base_type = field->type()->base_type();
|
||||||
|
|
||||||
// Generate some fixed strings so we don't repeat outselves later.
|
// Generate some fixed strings so we don't repeat outselves later.
|
||||||
@@ -367,9 +367,8 @@ class LuaBfbsGenerator : public BaseBfbsGenerator {
|
|||||||
ForAllFields(object, /*reverse=*/false, [&](const r::Field *field) {
|
ForAllFields(object, /*reverse=*/false, [&](const r::Field *field) {
|
||||||
if (field->deprecated()) { return; }
|
if (field->deprecated()) { return; }
|
||||||
|
|
||||||
const std::string field_name = namer_.Field(field->name()->str());
|
const std::string field_name = namer_.Field(*field);
|
||||||
const std::string variable_name =
|
const std::string variable_name = namer_.Variable(*field);
|
||||||
namer_.Variable(field->name()->str());
|
|
||||||
|
|
||||||
code += "function " + object_name + ".Add" + field_name +
|
code += "function " + object_name + ".Add" + field_name +
|
||||||
"(builder, " + variable_name + ")\n";
|
"(builder, " + variable_name + ")\n";
|
||||||
@@ -428,9 +427,9 @@ class LuaBfbsGenerator : public BaseBfbsGenerator {
|
|||||||
if (IsStructOrTable(field->type()->base_type())) {
|
if (IsStructOrTable(field->type()->base_type())) {
|
||||||
const r::Object *field_object = GetObject(field->type());
|
const r::Object *field_object = GetObject(field->type());
|
||||||
signature += GenerateStructBuilderArgs(
|
signature += GenerateStructBuilderArgs(
|
||||||
field_object, prefix + namer_.Variable(field->name()->str()) + "_");
|
field_object, prefix + namer_.Variable(*field) + "_");
|
||||||
} else {
|
} else {
|
||||||
signature += ", " + prefix + namer_.Variable(field->name()->str());
|
signature += ", " + prefix + namer_.Variable(*field);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return signature;
|
return signature;
|
||||||
@@ -451,11 +450,11 @@ class LuaBfbsGenerator : public BaseBfbsGenerator {
|
|||||||
}
|
}
|
||||||
if (IsStructOrTable(field->type()->base_type())) {
|
if (IsStructOrTable(field->type()->base_type())) {
|
||||||
const r::Object *field_object = GetObject(field->type());
|
const r::Object *field_object = GetObject(field->type());
|
||||||
code += AppendStructBuilderBody(
|
code += AppendStructBuilderBody(field_object,
|
||||||
field_object, prefix + namer_.Variable(field->name()->str()) + "_");
|
prefix + namer_.Variable(*field) + "_");
|
||||||
} else {
|
} else {
|
||||||
code += " builder:Prepend" + GenerateMethod(field) + "(" + prefix +
|
code += " builder:Prepend" + GenerateMethod(field) + "(" + prefix +
|
||||||
namer_.Variable(field->name()->str()) + ")\n";
|
namer_.Variable(*field) + ")\n";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
640
src/bfbs_gen_nim.cpp
Normal file
640
src/bfbs_gen_nim.cpp
Normal file
@@ -0,0 +1,640 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2021 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bfbs_gen_nim.h"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// Ensure no includes to flatc internals. bfbs_gen.h and generator.h are OK.
|
||||||
|
#include "bfbs_gen.h"
|
||||||
|
#include "bfbs_namer.h"
|
||||||
|
#include "flatbuffers/bfbs_generator.h"
|
||||||
|
|
||||||
|
// The intermediate representation schema.
|
||||||
|
#include "flatbuffers/reflection.h"
|
||||||
|
#include "flatbuffers/reflection_generated.h"
|
||||||
|
|
||||||
|
namespace flatbuffers {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// To reduce typing
|
||||||
|
namespace r = ::reflection;
|
||||||
|
|
||||||
|
std::set<std::string> NimKeywords() {
|
||||||
|
return {
|
||||||
|
"addr", "and", "as", "asm", "bind", "block",
|
||||||
|
"break", "case", "cast", "concept", "const", "continue",
|
||||||
|
"converter", "defer", "discard", "distinct", "div", "do",
|
||||||
|
"elif", "else", "end", "enum", "except", "export",
|
||||||
|
"finally", "for", "from", "func", "if", "import",
|
||||||
|
"in", "include", "interface", "is", "isnot", "iterator",
|
||||||
|
"let", "macro", "method", "mixin", "mod", "nil",
|
||||||
|
"not", "notin", "object", "of", "or", "out",
|
||||||
|
"proc", "ptr", "raise", "ref", "return", "shl",
|
||||||
|
"shr", "static", "template", "try", "tuple", "type",
|
||||||
|
"using", "var", "when", "while", "xor", "yield",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Namer::Config NimDefaultConfig() {
|
||||||
|
return { /*types=*/Case::kUpperCamel,
|
||||||
|
/*constants=*/Case::kUpperCamel,
|
||||||
|
/*methods=*/Case::kLowerCamel,
|
||||||
|
/*functions=*/Case::kUpperCamel,
|
||||||
|
/*fields=*/Case::kLowerCamel,
|
||||||
|
/*variable=*/Case::kLowerCamel,
|
||||||
|
/*variants=*/Case::kUpperCamel,
|
||||||
|
/*enum_variant_seperator=*/".",
|
||||||
|
/*escape_keywords=*/Namer::Config::Escape::AfterConvertingCase,
|
||||||
|
/*namespaces=*/Case::kKeep,
|
||||||
|
/*namespace_seperator=*/"/",
|
||||||
|
/*object_prefix=*/"",
|
||||||
|
/*object_suffix=*/"T",
|
||||||
|
/*keyword_prefix=*/"",
|
||||||
|
/*keyword_suffix=*/"_",
|
||||||
|
/*filenames=*/Case::kKeep,
|
||||||
|
/*directories=*/Case::kKeep,
|
||||||
|
/*output_path=*/"",
|
||||||
|
/*filename_suffix=*/"",
|
||||||
|
/*filename_extension=*/".nim" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string Indent = " ";
|
||||||
|
const std::string Export = "*";
|
||||||
|
const std::set<std::string> builtin_types = {
|
||||||
|
"uint8", "uint8", "bool", "int8", "uint8", "int16",
|
||||||
|
"uint16", "int32", "uint32", "int64", "uint64", "float32",
|
||||||
|
"float64", "string", "int", "uint", "uoffset", "Builder"
|
||||||
|
};
|
||||||
|
|
||||||
|
class NimBfbsGenerator : public BaseBfbsGenerator {
|
||||||
|
public:
|
||||||
|
explicit NimBfbsGenerator(const std::string &flatc_version)
|
||||||
|
: BaseBfbsGenerator(),
|
||||||
|
keywords_(),
|
||||||
|
imports_(),
|
||||||
|
current_obj_(nullptr),
|
||||||
|
current_enum_(nullptr),
|
||||||
|
flatc_version_(flatc_version),
|
||||||
|
namer_(NimDefaultConfig(), NimKeywords()) {}
|
||||||
|
|
||||||
|
GeneratorStatus GenerateFromSchema(const r::Schema *schema)
|
||||||
|
FLATBUFFERS_OVERRIDE {
|
||||||
|
ForAllEnums(schema->enums(), [&](const r::Enum *enum_def) {
|
||||||
|
StartCodeBlock(enum_def);
|
||||||
|
GenerateEnum(enum_def);
|
||||||
|
});
|
||||||
|
ForAllObjects(schema->objects(), [&](const r::Object *object) {
|
||||||
|
StartCodeBlock(object);
|
||||||
|
GenerateObject(object);
|
||||||
|
});
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t SupportedAdvancedFeatures() const FLATBUFFERS_OVERRIDE {
|
||||||
|
return r::AdvancedArrayFeatures | r::AdvancedUnionFeatures |
|
||||||
|
r::OptionalScalars | r::DefaultVectorsAndStrings;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void GenerateEnum(const r::Enum *enum_def) {
|
||||||
|
std::string code;
|
||||||
|
|
||||||
|
std::string ns;
|
||||||
|
const std::string enum_name = namer_.Type(namer_.Denamespace(enum_def, ns));
|
||||||
|
const std::string enum_type =
|
||||||
|
GenerateTypeBasic(enum_def->underlying_type());
|
||||||
|
|
||||||
|
GenerateDocumentation(enum_def->documentation(), "", code);
|
||||||
|
code += "type " + enum_name + Export + "{.pure.} = enum\n";
|
||||||
|
|
||||||
|
ForAllEnumValues(enum_def, [&](const reflection::EnumVal *enum_val) {
|
||||||
|
GenerateDocumentation(enum_val->documentation(), " ", code);
|
||||||
|
code += " " + namer_.Variant(enum_val->name()->str()) + " = " +
|
||||||
|
NumToString(enum_val->value()) + "." + enum_type + ",\n";
|
||||||
|
});
|
||||||
|
|
||||||
|
EmitCodeBlock(code, enum_name, ns, enum_def->declaration_file()->str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GenerateObject(const r::Object *object) {
|
||||||
|
// Register the main flatbuffers module.
|
||||||
|
RegisterImports("flatbuffers", "");
|
||||||
|
std::string code;
|
||||||
|
|
||||||
|
std::string ns;
|
||||||
|
const std::string object_name = namer_.Type(namer_.Denamespace(object, ns));
|
||||||
|
|
||||||
|
GenerateDocumentation(object->documentation(), "", code);
|
||||||
|
code += "type " + object_name + "* = object of FlatObj\n";
|
||||||
|
|
||||||
|
// Create all the field accessors.
|
||||||
|
ForAllFields(object, /*reverse=*/false, [&](const r::Field *field) {
|
||||||
|
// Skip writing deprecated fields altogether.
|
||||||
|
if (field->deprecated()) { return; }
|
||||||
|
|
||||||
|
const std::string field_name = namer_.Field(*field);
|
||||||
|
const r::BaseType base_type = field->type()->base_type();
|
||||||
|
std::string field_type = GenerateType(field->type());
|
||||||
|
|
||||||
|
if (field->optional() && !object->is_struct()) {
|
||||||
|
RegisterImports("std/options", "");
|
||||||
|
field_type = "Option[" + field_type + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string offset_prefix =
|
||||||
|
"let o = self.tab.Offset(" + NumToString(field->offset()) + ")\n";
|
||||||
|
const std::string offset_prefix_2 = "if o != 0:\n";
|
||||||
|
|
||||||
|
if (IsScalar(base_type) || base_type == r::String ||
|
||||||
|
base_type == r::Obj || base_type == r::Union) {
|
||||||
|
GenerateDocumentation(field->documentation(), "", code);
|
||||||
|
|
||||||
|
std::string getter_signature = "func " + namer_.Method(field_name) +
|
||||||
|
"*(self: " + object_name +
|
||||||
|
"): " + field_type + " =\n";
|
||||||
|
std::string getter_code;
|
||||||
|
std::string setter_signature =
|
||||||
|
"func `" + namer_.Method(field_name + "=") + "`*(self: var " +
|
||||||
|
object_name + ", n: " + field_type + "): bool =\n";
|
||||||
|
std::string setter_code;
|
||||||
|
|
||||||
|
if (base_type == r::Obj || base_type == r::Union ||
|
||||||
|
field->type()->index() >= 0) {
|
||||||
|
RegisterImports(object, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (object->is_struct()) {
|
||||||
|
std::string field_getter =
|
||||||
|
GenerateGetter(field->type(), NumToString(field->offset()));
|
||||||
|
getter_code += " return " + field_getter + "\n";
|
||||||
|
|
||||||
|
if (IsScalar(base_type)) {
|
||||||
|
setter_code += " return self.tab.Mutate(self.tab.Pos + " +
|
||||||
|
NumToString(field->offset()) + ", n)\n";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Table accessors
|
||||||
|
getter_code += " " + offset_prefix;
|
||||||
|
getter_code += " " + offset_prefix_2;
|
||||||
|
std::string field_getter = GenerateGetter(field->type(), "o");
|
||||||
|
if (field->optional()) {
|
||||||
|
field_getter = "some(" + field_getter + ")";
|
||||||
|
}
|
||||||
|
getter_code += " return " + field_getter + "\n";
|
||||||
|
if (!field->optional()) {
|
||||||
|
getter_code += " return " + DefaultValue(field) + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsScalar(base_type)) {
|
||||||
|
setter_code += " return self.tab.MutateSlot(" +
|
||||||
|
NumToString(field->offset()) + ", n)\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
code += getter_signature + getter_code;
|
||||||
|
if (IsScalar(base_type)) { code += setter_signature + setter_code; }
|
||||||
|
} else if (base_type == r::Array || base_type == r::Vector) {
|
||||||
|
const r::BaseType vector_base_type = field->type()->element();
|
||||||
|
uint32_t element_size = field->type()->element_size();
|
||||||
|
|
||||||
|
if (vector_base_type == r::Obj || vector_base_type == r::Union ||
|
||||||
|
field->type()->index() >= 0) {
|
||||||
|
RegisterImports(object, field, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get vector length:
|
||||||
|
code += "func " + namer_.Method(field_name + "Length") +
|
||||||
|
"*(self: " + object_name + "): int = \n";
|
||||||
|
code += " " + offset_prefix;
|
||||||
|
code += " " + offset_prefix_2;
|
||||||
|
code += " return self.tab.VectorLen(o)\n";
|
||||||
|
|
||||||
|
// Get single vector field:
|
||||||
|
code += "func " + namer_.Method(field_name) + "*(self: " + object_name +
|
||||||
|
", j: int): " + GenerateType(field->type(), true) + " = \n";
|
||||||
|
code += " " + offset_prefix;
|
||||||
|
code += " " + offset_prefix_2;
|
||||||
|
code += " var x = self.tab.Vector(o)\n";
|
||||||
|
code +=
|
||||||
|
" x += j.uoffset * " + NumToString(element_size) + ".uoffset\n";
|
||||||
|
code += " return " + GenerateGetter(field->type(), "x", true) + "\n";
|
||||||
|
|
||||||
|
// Get entire vector:
|
||||||
|
code += "func " + namer_.Method(field_name) + "*(self: " + object_name +
|
||||||
|
"): " + GenerateType(field->type()) + " = \n";
|
||||||
|
code += " let len = self." + field_name + "Length\n";
|
||||||
|
code += " for i in countup(0, len - 1):\n";
|
||||||
|
code += " result.add(self." + field_name + "(i))\n";
|
||||||
|
|
||||||
|
(void)IsSingleByte(vector_base_type); // unnused function warning
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create all the builders
|
||||||
|
if (object->is_struct()) {
|
||||||
|
code += "proc " + namer_.Function(object_name + "Create") +
|
||||||
|
"*(self: var Builder";
|
||||||
|
code += GenerateStructBuilderArgs(object);
|
||||||
|
code += "): uoffset =\n";
|
||||||
|
code += AppendStructBuilderBody(object);
|
||||||
|
code += " return self.Offset()\n";
|
||||||
|
} else {
|
||||||
|
// Table builders
|
||||||
|
code += "proc " + namer_.Function(object_name + "Start") +
|
||||||
|
"*(builder: var Builder) =\n";
|
||||||
|
code += " builder.StartObject(" + NumToString(object->fields()->size()) +
|
||||||
|
")\n";
|
||||||
|
|
||||||
|
ForAllFields(object, /*reverse=*/false, [&](const r::Field *field) {
|
||||||
|
if (field->deprecated()) { return; }
|
||||||
|
|
||||||
|
const std::string field_name = namer_.Field(*field);
|
||||||
|
const std::string variable_name = namer_.Variable(*field);
|
||||||
|
const std::string variable_type = GenerateTypeBasic(field->type());
|
||||||
|
|
||||||
|
code += "proc " + namer_.Function(object_name + "Add" + field_name) +
|
||||||
|
"*(builder: var Builder, " + variable_name + ": " +
|
||||||
|
variable_type + ") =\n";
|
||||||
|
code += " builder.Prepend" + GenerateMethod(field) + "Slot(" +
|
||||||
|
NumToString(field->id()) + ", " + variable_name + ", default(" +
|
||||||
|
variable_type + "))\n";
|
||||||
|
|
||||||
|
if (IsVector(field->type()->base_type())) {
|
||||||
|
code += "proc " +
|
||||||
|
namer_.Function(object_name + "Start" + field_name) +
|
||||||
|
"Vector*(builder: var Builder, numElems: uoffset) =\n";
|
||||||
|
|
||||||
|
const int32_t element_size = field->type()->element_size();
|
||||||
|
int32_t alignment = element_size;
|
||||||
|
if (IsStruct(field->type(), /*use_element=*/true)) {
|
||||||
|
alignment = GetObjectByIndex(field->type()->index())->minalign();
|
||||||
|
}
|
||||||
|
|
||||||
|
code += " builder.StartVector(" + NumToString(element_size) +
|
||||||
|
", numElems, " + NumToString(alignment) + ")\n";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
code += "proc " + namer_.Function(object_name + "End") +
|
||||||
|
"*(builder: var Builder): uoffset =\n";
|
||||||
|
code += " return builder.EndObject()\n";
|
||||||
|
}
|
||||||
|
EmitCodeBlock(code, object_name, ns, object->declaration_file()->str());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void GenerateDocumentation(
|
||||||
|
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>
|
||||||
|
*documentation,
|
||||||
|
std::string indent, std::string &code) const {
|
||||||
|
flatbuffers::ForAllDocumentation(
|
||||||
|
documentation, [&](const flatbuffers::String *str) {
|
||||||
|
code += indent + "# " + str->str() + "\n";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GenerateStructBuilderArgs(const r::Object *object,
|
||||||
|
std::string prefix = "") const {
|
||||||
|
std::string signature;
|
||||||
|
ForAllFields(object, /*reverse=*/false, [&](const r::Field *field) {
|
||||||
|
if (IsStructOrTable(field->type()->base_type())) {
|
||||||
|
const r::Object *field_object = GetObject(field->type());
|
||||||
|
signature += GenerateStructBuilderArgs(
|
||||||
|
field_object, prefix + namer_.Variable(*field) + "_");
|
||||||
|
} else {
|
||||||
|
signature += ", " + prefix + namer_.Variable(*field) + ": " +
|
||||||
|
GenerateType(field->type());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return signature;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string AppendStructBuilderBody(const r::Object *object,
|
||||||
|
std::string prefix = "") const {
|
||||||
|
std::string code;
|
||||||
|
code += " self.Prep(" + NumToString(object->minalign()) + ", " +
|
||||||
|
NumToString(object->bytesize()) + ")\n";
|
||||||
|
|
||||||
|
// We need to reverse the order we iterate over, since we build the
|
||||||
|
// buffer backwards.
|
||||||
|
ForAllFields(object, /*reverse=*/true, [&](const r::Field *field) {
|
||||||
|
const int32_t num_padding_bytes = field->padding();
|
||||||
|
if (num_padding_bytes) {
|
||||||
|
code += " self.Pad(" + NumToString(num_padding_bytes) + ")\n";
|
||||||
|
}
|
||||||
|
if (IsStructOrTable(field->type()->base_type())) {
|
||||||
|
const r::Object *field_object = GetObject(field->type());
|
||||||
|
code += AppendStructBuilderBody(field_object,
|
||||||
|
prefix + namer_.Variable(*field) + "_");
|
||||||
|
} else {
|
||||||
|
code += " self.Prepend(" + prefix + namer_.Variable(*field) + ")\n";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GenerateMethod(const r::Field *field) const {
|
||||||
|
const r::BaseType base_type = field->type()->base_type();
|
||||||
|
if (IsStructOrTable(base_type)) { return "Struct"; }
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GenerateGetter(const r::Type *type, const std::string &offsetval,
|
||||||
|
bool element_type = false) const {
|
||||||
|
const r::BaseType base_type =
|
||||||
|
element_type ? type->element() : type->base_type();
|
||||||
|
std::string offset = offsetval;
|
||||||
|
if (!element_type) { offset = "self.tab.Pos + " + offset; }
|
||||||
|
switch (base_type) {
|
||||||
|
case r::String: return "self.tab.String(" + offset + ")";
|
||||||
|
case r::Union: return "self.tab.Union(" + offsetval + ")";
|
||||||
|
case r::Obj: {
|
||||||
|
return GenerateType(type, element_type) +
|
||||||
|
"(tab: Vtable(Bytes: self.tab.Bytes, Pos: " + offset + "))";
|
||||||
|
}
|
||||||
|
case r::Vector: return GenerateGetter(type, offsetval, true);
|
||||||
|
default:
|
||||||
|
const r::Enum *type_enum = GetEnum(type, element_type);
|
||||||
|
if (type_enum != nullptr) {
|
||||||
|
return GenerateType(type, element_type) + "(" + "Get[" +
|
||||||
|
GenerateType(base_type) + "](self.tab, " + offset + ")" + ")";
|
||||||
|
} else {
|
||||||
|
return "Get[" + GenerateType(base_type) + "](self.tab, " + offset +
|
||||||
|
")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Denamespace(const std::string &s, std::string &importns,
|
||||||
|
std::string &ns) const {
|
||||||
|
if (builtin_types.find(s) != builtin_types.end()) { return s; }
|
||||||
|
std::string type = namer_.Type(namer_.Denamespace(s, ns));
|
||||||
|
importns = ns.empty() ? type : ns + "." + type;
|
||||||
|
std::replace(importns.begin(), importns.end(), '.', '_');
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Denamespace(const std::string &s, std::string &importns) const {
|
||||||
|
std::string ns;
|
||||||
|
return Denamespace(s, importns, ns);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Denamespace(const std::string &s) const {
|
||||||
|
std::string importns;
|
||||||
|
return Denamespace(s, importns);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GenerateType(const r::Type *type, bool element_type = false,
|
||||||
|
bool enum_inner = false) const {
|
||||||
|
const r::BaseType base_type =
|
||||||
|
element_type ? type->element() : type->base_type();
|
||||||
|
if (IsScalar(base_type) && !enum_inner) {
|
||||||
|
const r::Enum *type_enum = GetEnum(type, element_type);
|
||||||
|
if (type_enum != nullptr) {
|
||||||
|
std::string importns;
|
||||||
|
std::string type_name = Denamespace(type_enum->name()->str(), importns);
|
||||||
|
return importns + "." + type_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (IsScalar(base_type)) { return Denamespace(GenerateType(base_type)); }
|
||||||
|
switch (base_type) {
|
||||||
|
case r::String: return "string";
|
||||||
|
case r::Vector: {
|
||||||
|
return "seq[" + GenerateType(type, true) + "]";
|
||||||
|
}
|
||||||
|
case r::Union: return "Vtable";
|
||||||
|
case r::Obj: {
|
||||||
|
const r::Object *type_obj = GetObject(type, element_type);
|
||||||
|
std::string importns;
|
||||||
|
std::string type_name = Denamespace(type_obj->name()->str(), importns);
|
||||||
|
if (type_obj == current_obj_) {
|
||||||
|
return type_name;
|
||||||
|
} else {
|
||||||
|
return importns + "." + type_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: return "uoffset";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GenerateTypeBasic(const r::Type *type,
|
||||||
|
bool element_type = false) const {
|
||||||
|
const r::BaseType base_type =
|
||||||
|
element_type ? type->element() : type->base_type();
|
||||||
|
if (IsScalar(base_type)) {
|
||||||
|
return GenerateType(base_type);
|
||||||
|
} else {
|
||||||
|
return "uoffset";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GenerateType(const r::BaseType base_type) const {
|
||||||
|
switch (base_type) {
|
||||||
|
case r::None: return "uint8";
|
||||||
|
case r::UType: return "uint8";
|
||||||
|
case r::Bool: return "bool";
|
||||||
|
case r::Byte: return "int8";
|
||||||
|
case r::UByte: return "uint8";
|
||||||
|
case r::Short: return "int16";
|
||||||
|
case r::UShort: return "uint16";
|
||||||
|
case r::Int: return "int32";
|
||||||
|
case r::UInt: return "uint32";
|
||||||
|
case r::Long: return "int64";
|
||||||
|
case r::ULong: return "uint64";
|
||||||
|
case r::Float: return "float32";
|
||||||
|
case r::Double: return "float64";
|
||||||
|
case r::String: return "string";
|
||||||
|
default: return r::EnumNameBaseType(base_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string DefaultValue(const r::Field *field) const {
|
||||||
|
const r::BaseType base_type = field->type()->base_type();
|
||||||
|
if (IsFloatingPoint(base_type)) {
|
||||||
|
return NumToString(field->default_real());
|
||||||
|
}
|
||||||
|
if (IsBool(base_type)) {
|
||||||
|
return field->default_integer() ? "true" : "false";
|
||||||
|
}
|
||||||
|
if (IsScalar(base_type)) {
|
||||||
|
const r::Enum *type_enum = GetEnum(field->type());
|
||||||
|
if (type_enum != nullptr) {
|
||||||
|
return "type(result)(" + NumToString((field->default_integer())) + ")";
|
||||||
|
}
|
||||||
|
return NumToString((field->default_integer()));
|
||||||
|
}
|
||||||
|
if (base_type == r::String) { return "\"\""; }
|
||||||
|
// represents offsets
|
||||||
|
return "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartCodeBlock(const reflection::Enum *enum_def) {
|
||||||
|
current_enum_ = enum_def;
|
||||||
|
current_obj_ = nullptr;
|
||||||
|
imports_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartCodeBlock(const reflection::Object *object) {
|
||||||
|
current_enum_ = nullptr;
|
||||||
|
current_obj_ = object;
|
||||||
|
imports_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> StringSplit(const std::string orig_str,
|
||||||
|
const std::string token) {
|
||||||
|
std::vector<std::string> result;
|
||||||
|
std::string str = orig_str;
|
||||||
|
while (str.size()) {
|
||||||
|
size_t index = str.find(token);
|
||||||
|
if (index != std::string::npos) {
|
||||||
|
result.push_back(str.substr(0, index));
|
||||||
|
str = str.substr(index + token.size());
|
||||||
|
if (str.size() == 0) result.push_back(str);
|
||||||
|
} else {
|
||||||
|
result.push_back(str);
|
||||||
|
str = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetRelativePathFromNamespace(const std::string &relative_to,
|
||||||
|
const std::string &str2) {
|
||||||
|
std::vector<std::string> relative_to_vec = StringSplit(relative_to, ".");
|
||||||
|
std::vector<std::string> str2_vec = StringSplit(str2, ".");
|
||||||
|
while (relative_to_vec.size() > 0 && str2_vec.size() > 0) {
|
||||||
|
if (relative_to_vec[0] == str2_vec[0]) {
|
||||||
|
relative_to_vec.erase(relative_to_vec.begin());
|
||||||
|
str2_vec.erase(str2_vec.begin());
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
relative_to_vec.pop_back();
|
||||||
|
for (size_t i = 0; i < relative_to_vec.size(); ++i) {
|
||||||
|
str2_vec.insert(str2_vec.begin(), std::string(".."));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string new_path;
|
||||||
|
for (size_t i = 0; i < str2_vec.size(); ++i) {
|
||||||
|
new_path += str2_vec[i];
|
||||||
|
if (i != str2_vec.size() - 1) { new_path += "/"; }
|
||||||
|
}
|
||||||
|
return new_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegisterImports(const r::Object *object, const r::Field *field,
|
||||||
|
bool use_element = false) {
|
||||||
|
std::string importns;
|
||||||
|
std::string type_name;
|
||||||
|
|
||||||
|
const r::BaseType type =
|
||||||
|
use_element ? field->type()->element() : field->type()->base_type();
|
||||||
|
|
||||||
|
if (IsStructOrTable(type)) {
|
||||||
|
const r::Object *object_def = GetObjectByIndex(field->type()->index());
|
||||||
|
if (object_def == current_obj_) { return; }
|
||||||
|
std::string ns;
|
||||||
|
type_name = Denamespace(object_def->name()->str(), importns, ns);
|
||||||
|
type_name = ns.empty() ? type_name : ns + "." + type_name;
|
||||||
|
} else {
|
||||||
|
const r::Enum *enum_def = GetEnumByIndex(field->type()->index());
|
||||||
|
if (enum_def == current_enum_) { return; }
|
||||||
|
std::string ns;
|
||||||
|
type_name = Denamespace(enum_def->name()->str(), importns, ns);
|
||||||
|
type_name = ns.empty() ? type_name : ns + "." + type_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string import_path =
|
||||||
|
GetRelativePathFromNamespace(object->name()->str(), type_name);
|
||||||
|
std::replace(type_name.begin(), type_name.end(), '.', '_');
|
||||||
|
RegisterImports(import_path, importns);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegisterImports(const std::string &local_name,
|
||||||
|
const std::string &imports_name) {
|
||||||
|
imports_[local_name] = imports_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EmitCodeBlock(const std::string &code_block, const std::string &name,
|
||||||
|
const std::string &ns, const std::string &declaring_file) {
|
||||||
|
const std::string full_qualified_name = ns.empty() ? name : ns + "." + name;
|
||||||
|
|
||||||
|
std::string code = "#[ " + full_qualified_name + "\n";
|
||||||
|
code +=
|
||||||
|
" Automatically generated by the FlatBuffers compiler, do not "
|
||||||
|
"modify.\n";
|
||||||
|
code += " Or modify. I'm a message, not a cop.\n";
|
||||||
|
code += "\n";
|
||||||
|
code += " flatc version: " + flatc_version_ + "\n";
|
||||||
|
code += "\n";
|
||||||
|
code += " Declared by : " + declaring_file + "\n";
|
||||||
|
if (schema_->root_table() != nullptr) {
|
||||||
|
const std::string root_type = schema_->root_table()->name()->str();
|
||||||
|
const std::string root_file =
|
||||||
|
schema_->root_table()->declaration_file()->str();
|
||||||
|
code += " Rooting type : " + root_type + " (" + root_file + ")\n";
|
||||||
|
}
|
||||||
|
code += "]#\n\n";
|
||||||
|
|
||||||
|
if (!imports_.empty()) {
|
||||||
|
for (auto it = imports_.cbegin(); it != imports_.cend(); ++it) {
|
||||||
|
if (it->second.empty()) {
|
||||||
|
code += "import " + it->first + "\n";
|
||||||
|
} else {
|
||||||
|
code += "import " + it->first + " as " + it->second + "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
code += "\n";
|
||||||
|
}
|
||||||
|
code += code_block;
|
||||||
|
|
||||||
|
// Namespaces are '.' deliminted, so replace it with the path separator.
|
||||||
|
std::string path = ns;
|
||||||
|
|
||||||
|
if (ns.empty()) {
|
||||||
|
path = ".";
|
||||||
|
} else {
|
||||||
|
std::replace(path.begin(), path.end(), '.', '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(derekbailey): figure out a save file without depending on util.h
|
||||||
|
EnsureDirExists(path);
|
||||||
|
const std::string file_name = path + "/" + namer_.File(name);
|
||||||
|
SaveFile(file_name.c_str(), code, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unordered_set<std::string> keywords_;
|
||||||
|
std::map<std::string, std::string> imports_;
|
||||||
|
const r::Object *current_obj_;
|
||||||
|
const r::Enum *current_enum_;
|
||||||
|
const std::string flatc_version_;
|
||||||
|
const BfbsNamer namer_;
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
std::unique_ptr<BfbsGenerator> NewNimBfbsGenerator(
|
||||||
|
const std::string &flatc_version) {
|
||||||
|
return std::unique_ptr<NimBfbsGenerator>(new NimBfbsGenerator(flatc_version));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace flatbuffers
|
||||||
33
src/bfbs_gen_nim.h
Normal file
33
src/bfbs_gen_nim.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2021 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLATBUFFERS_BFBS_GEN_NIM_H_
|
||||||
|
#define FLATBUFFERS_BFBS_GEN_NIM_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "flatbuffers/bfbs_generator.h"
|
||||||
|
|
||||||
|
namespace flatbuffers {
|
||||||
|
|
||||||
|
// Constructs a new Nim Code generator.
|
||||||
|
std::unique_ptr<BfbsGenerator> NewNimBfbsGenerator(
|
||||||
|
const std::string &flatc_version);
|
||||||
|
|
||||||
|
} // namespace flatbuffers
|
||||||
|
|
||||||
|
#endif // FLATBUFFERS_BFBS_GEN_NIM_H_
|
||||||
@@ -36,6 +36,14 @@ class BfbsNamer : public Namer {
|
|||||||
std::string Denamespace(T t, const char delimiter = '.') const {
|
std::string Denamespace(T t, const char delimiter = '.') const {
|
||||||
return Namer::Denamespace(t->name()->c_str(), delimiter);
|
return Namer::Denamespace(t->name()->c_str(), delimiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual std::string Field(const ::reflection::Field &f) const {
|
||||||
|
return Field(f.name()->str());
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual std::string Variable(const ::reflection::Field &f) const {
|
||||||
|
return Variable(f.name()->str());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace flatbuffers
|
} // namespace flatbuffers
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "bfbs_gen_lua.h"
|
#include "bfbs_gen_lua.h"
|
||||||
|
#include "bfbs_gen_nim.h"
|
||||||
#include "flatbuffers/base.h"
|
#include "flatbuffers/base.h"
|
||||||
#include "flatbuffers/flatc.h"
|
#include "flatbuffers/flatc.h"
|
||||||
#include "flatbuffers/util.h"
|
#include "flatbuffers/util.h"
|
||||||
@@ -56,6 +57,8 @@ int main(int argc, const char *argv[]) {
|
|||||||
|
|
||||||
std::unique_ptr<flatbuffers::BfbsGenerator> bfbs_gen_lua =
|
std::unique_ptr<flatbuffers::BfbsGenerator> bfbs_gen_lua =
|
||||||
flatbuffers::NewLuaBfbsGenerator(flatbuffers_version);
|
flatbuffers::NewLuaBfbsGenerator(flatbuffers_version);
|
||||||
|
std::unique_ptr<flatbuffers::BfbsGenerator> bfbs_gen_nim =
|
||||||
|
flatbuffers::NewNimBfbsGenerator(flatbuffers_version);
|
||||||
|
|
||||||
g_program_name = argv[0];
|
g_program_name = argv[0];
|
||||||
|
|
||||||
@@ -142,6 +145,10 @@ int main(int argc, const char *argv[]) {
|
|||||||
flatbuffers::FlatCOption{ "", "swift", "",
|
flatbuffers::FlatCOption{ "", "swift", "",
|
||||||
"Generate Swift files for tables/structs" },
|
"Generate Swift files for tables/structs" },
|
||||||
nullptr, nullptr, nullptr },
|
nullptr, nullptr, nullptr },
|
||||||
|
{ nullptr, "Nim", true, nullptr, flatbuffers::IDLOptions::kNim,
|
||||||
|
flatbuffers::FlatCOption{ "", "nim", "",
|
||||||
|
"Generate Nim files for tables/structs" },
|
||||||
|
nullptr, bfbs_gen_nim.get(), nullptr },
|
||||||
};
|
};
|
||||||
|
|
||||||
flatbuffers::FlatCompiler::InitParams params;
|
flatbuffers::FlatCompiler::InitParams params;
|
||||||
|
|||||||
@@ -655,7 +655,7 @@ class CSharpGenerator : public BaseGenerator {
|
|||||||
// Force compile time error if not using the same version runtime.
|
// Force compile time error if not using the same version runtime.
|
||||||
code += " public static void ValidateVersion() {";
|
code += " public static void ValidateVersion() {";
|
||||||
code += " FlatBufferConstants.";
|
code += " FlatBufferConstants.";
|
||||||
code += "FLATBUFFERS_22_9_29(); ";
|
code += "FLATBUFFERS_22_10_26(); ";
|
||||||
code += "}\n";
|
code += "}\n";
|
||||||
|
|
||||||
// Generate a special accessor for the table that when used as the root
|
// Generate a special accessor for the table that when used as the root
|
||||||
|
|||||||
@@ -397,6 +397,10 @@ class JavaGenerator : public BaseGenerator {
|
|||||||
code += " ";
|
code += " ";
|
||||||
code += namer_.Variant(ev) + " = ";
|
code += namer_.Variant(ev) + " = ";
|
||||||
code += enum_def.ToString(ev);
|
code += enum_def.ToString(ev);
|
||||||
|
if (enum_def.underlying_type.base_type == BASE_TYPE_LONG ||
|
||||||
|
enum_def.underlying_type.base_type == BASE_TYPE_ULONG) {
|
||||||
|
code += "L";
|
||||||
|
}
|
||||||
code += ";\n";
|
code += ";\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -665,7 +669,7 @@ class JavaGenerator : public BaseGenerator {
|
|||||||
// Force compile time error if not using the same version runtime.
|
// Force compile time error if not using the same version runtime.
|
||||||
code += " public static void ValidateVersion() {";
|
code += " public static void ValidateVersion() {";
|
||||||
code += " Constants.";
|
code += " Constants.";
|
||||||
code += "FLATBUFFERS_22_9_29(); ";
|
code += "FLATBUFFERS_22_10_26(); ";
|
||||||
code += "}\n";
|
code += "}\n";
|
||||||
|
|
||||||
// Generate a special accessor for the table that when used as the root
|
// Generate a special accessor for the table that when used as the root
|
||||||
@@ -1889,6 +1893,7 @@ class JavaGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
code += " " + name + " = ";
|
code += " " + name + " = ";
|
||||||
|
code += SourceCast(field_type);
|
||||||
code += "_o";
|
code += "_o";
|
||||||
for (size_t i = 0; i < array_lengths.size(); ++i) {
|
for (size_t i = 0; i < array_lengths.size(); ++i) {
|
||||||
code += "." + namer_.Method("get", array_lengths[i].name) + "()";
|
code += "." + namer_.Method("get", array_lengths[i].name) + "()";
|
||||||
|
|||||||
@@ -505,7 +505,7 @@ class KotlinGenerator : public BaseGenerator {
|
|||||||
// runtime.
|
// runtime.
|
||||||
GenerateFunOneLine(
|
GenerateFunOneLine(
|
||||||
writer, "validateVersion", "", "",
|
writer, "validateVersion", "", "",
|
||||||
[&]() { writer += "Constants.FLATBUFFERS_22_9_29()"; },
|
[&]() { writer += "Constants.FLATBUFFERS_22_10_26()"; },
|
||||||
options.gen_jvmstatic);
|
options.gen_jvmstatic);
|
||||||
|
|
||||||
GenerateGetRootAsAccessors(namer_.Type(struct_def), writer, options);
|
GenerateGetRootAsAccessors(namer_.Type(struct_def), writer, options);
|
||||||
|
|||||||
@@ -1108,13 +1108,25 @@ class PythonGenerator : public BaseGenerator {
|
|||||||
|
|
||||||
code += GenIndents(1) + "@classmethod";
|
code += GenIndents(1) + "@classmethod";
|
||||||
code += GenIndents(1) + "def InitFromBuf(cls, buf, pos):";
|
code += GenIndents(1) + "def InitFromBuf(cls, buf, pos):";
|
||||||
code += GenIndents(2) + "n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)";
|
|
||||||
code += GenIndents(2) + struct_var + " = " + struct_type + "()";
|
code += GenIndents(2) + struct_var + " = " + struct_type + "()";
|
||||||
code += GenIndents(2) + struct_var + ".Init(buf, pos+n)";
|
code += GenIndents(2) + struct_var + ".Init(buf, pos)";
|
||||||
code += GenIndents(2) + "return cls.InitFromObj(" + struct_var + ")";
|
code += GenIndents(2) + "return cls.InitFromObj(" + struct_var + ")";
|
||||||
code += "\n";
|
code += "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InitializeFromPackedBuf(const StructDef &struct_def,
|
||||||
|
std::string *code_ptr) const {
|
||||||
|
auto &code = *code_ptr;
|
||||||
|
const auto struct_var = namer_.Variable(struct_def);
|
||||||
|
const auto struct_type = namer_.Type(struct_def);
|
||||||
|
|
||||||
|
code += GenIndents(1) + "@classmethod";
|
||||||
|
code += GenIndents(1) + "def InitFromPackedBuf(cls, buf, pos=0):";
|
||||||
|
code += GenIndents(2) + "n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)";
|
||||||
|
code += GenIndents(2) + "return cls.InitFromBuf(buf, pos+n)";
|
||||||
|
code += "\n";
|
||||||
|
}
|
||||||
|
|
||||||
void InitializeFromObjForObject(const StructDef &struct_def,
|
void InitializeFromObjForObject(const StructDef &struct_def,
|
||||||
std::string *code_ptr) const {
|
std::string *code_ptr) const {
|
||||||
auto &code = *code_ptr;
|
auto &code = *code_ptr;
|
||||||
@@ -1607,6 +1619,8 @@ class PythonGenerator : public BaseGenerator {
|
|||||||
|
|
||||||
InitializeFromBuf(struct_def, &code);
|
InitializeFromBuf(struct_def, &code);
|
||||||
|
|
||||||
|
InitializeFromPackedBuf(struct_def, &code);
|
||||||
|
|
||||||
InitializeFromObjForObject(struct_def, &code);
|
InitializeFromObjForObject(struct_def, &code);
|
||||||
|
|
||||||
GenUnPack(struct_def, &code);
|
GenUnPack(struct_def, &code);
|
||||||
|
|||||||
@@ -1874,7 +1874,7 @@ class SwiftGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string ValidateFunc() {
|
std::string ValidateFunc() {
|
||||||
return "static func validateVersion() { FlatBuffersVersion_22_9_29() }";
|
return "static func validateVersion() { FlatBuffersVersion_22_10_26() }";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GenType(const Type &type,
|
std::string GenType(const Type &type,
|
||||||
|
|||||||
@@ -1584,7 +1584,6 @@ CheckedError Parser::ParseVectorDelimiters(uoffset_t &count, F body) {
|
|||||||
return NoError();
|
return NoError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CheckedError Parser::ParseAlignAttribute(const std::string &align_constant,
|
CheckedError Parser::ParseAlignAttribute(const std::string &align_constant,
|
||||||
size_t min_align, size_t *align) {
|
size_t min_align, size_t *align) {
|
||||||
// Use uint8_t to avoid problems with size_t==`unsigned long` on LP64.
|
// Use uint8_t to avoid problems with size_t==`unsigned long` on LP64.
|
||||||
@@ -2450,14 +2449,17 @@ CheckedError Parser::ParseEnum(const bool is_union, EnumDef **dest,
|
|||||||
EXPECT(kTokenIntegerConstant);
|
EXPECT(kTokenIntegerConstant);
|
||||||
}
|
}
|
||||||
|
|
||||||
ECHECK(evb.AcceptEnumerator());
|
|
||||||
|
|
||||||
if (opts.proto_mode && Is('[')) {
|
if (opts.proto_mode && Is('[')) {
|
||||||
NEXT();
|
NEXT();
|
||||||
// ignore attributes on enums.
|
// ignore attributes on enums.
|
||||||
while (token_ != ']') NEXT();
|
while (token_ != ']') NEXT();
|
||||||
NEXT();
|
NEXT();
|
||||||
|
} else {
|
||||||
|
// parse attributes in fbs schema
|
||||||
|
ECHECK(ParseMetaData(&ev.attributes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ECHECK(evb.AcceptEnumerator());
|
||||||
}
|
}
|
||||||
if (!Is(opts.proto_mode ? ';' : ',')) break;
|
if (!Is(opts.proto_mode ? ';' : ',')) break;
|
||||||
NEXT();
|
NEXT();
|
||||||
@@ -2552,7 +2554,8 @@ bool Parser::SupportsOptionalScalars(const flatbuffers::IDLOptions &opts) {
|
|||||||
IDLOptions::kRust | IDLOptions::kSwift | IDLOptions::kLobster |
|
IDLOptions::kRust | IDLOptions::kSwift | IDLOptions::kLobster |
|
||||||
IDLOptions::kKotlin | IDLOptions::kCpp | IDLOptions::kJava |
|
IDLOptions::kKotlin | IDLOptions::kCpp | IDLOptions::kJava |
|
||||||
IDLOptions::kCSharp | IDLOptions::kTs | IDLOptions::kBinary |
|
IDLOptions::kCSharp | IDLOptions::kTs | IDLOptions::kBinary |
|
||||||
IDLOptions::kGo | IDLOptions::kPython | IDLOptions::kJson;
|
IDLOptions::kGo | IDLOptions::kPython | IDLOptions::kJson |
|
||||||
|
IDLOptions::kNim;
|
||||||
unsigned long langs = opts.lang_to_generate;
|
unsigned long langs = opts.lang_to_generate;
|
||||||
return (langs > 0 && langs < IDLOptions::kMAX) && !(langs & ~supported_langs);
|
return (langs > 0 && langs < IDLOptions::kMAX) && !(langs & ~supported_langs);
|
||||||
}
|
}
|
||||||
@@ -2563,7 +2566,7 @@ bool Parser::SupportsOptionalScalars() const {
|
|||||||
|
|
||||||
bool Parser::SupportsDefaultVectorsAndStrings() const {
|
bool Parser::SupportsDefaultVectorsAndStrings() const {
|
||||||
static FLATBUFFERS_CONSTEXPR unsigned long supported_langs =
|
static FLATBUFFERS_CONSTEXPR unsigned long supported_langs =
|
||||||
IDLOptions::kRust | IDLOptions::kSwift;
|
IDLOptions::kRust | IDLOptions::kSwift | IDLOptions::kNim;
|
||||||
return !(opts.lang_to_generate & ~supported_langs);
|
return !(opts.lang_to_generate & ~supported_langs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2571,7 +2574,7 @@ bool Parser::SupportsAdvancedUnionFeatures() const {
|
|||||||
return (opts.lang_to_generate &
|
return (opts.lang_to_generate &
|
||||||
~(IDLOptions::kCpp | IDLOptions::kTs | IDLOptions::kPhp |
|
~(IDLOptions::kCpp | IDLOptions::kTs | IDLOptions::kPhp |
|
||||||
IDLOptions::kJava | IDLOptions::kCSharp | IDLOptions::kKotlin |
|
IDLOptions::kJava | IDLOptions::kCSharp | IDLOptions::kKotlin |
|
||||||
IDLOptions::kBinary | IDLOptions::kSwift)) == 0;
|
IDLOptions::kBinary | IDLOptions::kSwift | IDLOptions::kNim)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Parser::SupportsAdvancedArrayFeatures() const {
|
bool Parser::SupportsAdvancedArrayFeatures() const {
|
||||||
@@ -3415,7 +3418,6 @@ CheckedError Parser::CheckPrivatelyLeakedFields(const Definition &def,
|
|||||||
return NoError();
|
return NoError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CheckedError Parser::DoParse(const char *source, const char **include_paths,
|
CheckedError Parser::DoParse(const char *source, const char **include_paths,
|
||||||
const char *source_filename,
|
const char *source_filename,
|
||||||
const char *include_filename) {
|
const char *include_filename) {
|
||||||
@@ -3633,6 +3635,44 @@ std::set<std::string> Parser::GetIncludedFilesRecursive(
|
|||||||
|
|
||||||
// Schema serialization functionality:
|
// Schema serialization functionality:
|
||||||
|
|
||||||
|
static flatbuffers::Offset<
|
||||||
|
flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>>
|
||||||
|
SerializeAttributesCommon(const SymbolTable<Value> &attributes,
|
||||||
|
FlatBufferBuilder *builder, const Parser &parser) {
|
||||||
|
std::vector<flatbuffers::Offset<reflection::KeyValue>> attrs;
|
||||||
|
for (auto kv = attributes.dict.begin(); kv != attributes.dict.end(); ++kv) {
|
||||||
|
auto it = parser.known_attributes_.find(kv->first);
|
||||||
|
FLATBUFFERS_ASSERT(it != parser.known_attributes_.end());
|
||||||
|
if (parser.opts.binary_schema_builtins || !it->second) {
|
||||||
|
auto key = builder->CreateString(kv->first);
|
||||||
|
auto val = builder->CreateString(kv->second->constant);
|
||||||
|
attrs.push_back(reflection::CreateKeyValue(*builder, key, val));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (attrs.size()) {
|
||||||
|
return builder->CreateVectorOfSortedTables(&attrs);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool DeserializeAttributesCommon(
|
||||||
|
SymbolTable<Value> &attributes, Parser &parser,
|
||||||
|
const Vector<Offset<reflection::KeyValue>> *attrs) {
|
||||||
|
if (attrs == nullptr) return true;
|
||||||
|
for (uoffset_t i = 0; i < attrs->size(); ++i) {
|
||||||
|
auto kv = attrs->Get(i);
|
||||||
|
auto value = new Value();
|
||||||
|
if (kv->value()) { value->constant = kv->value()->str(); }
|
||||||
|
if (attributes.Add(kv->key()->str(), value)) {
|
||||||
|
delete value;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
parser.known_attributes_[kv->key()->str()];
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Parser::Serialize() {
|
void Parser::Serialize() {
|
||||||
builder_.Clear();
|
builder_.Clear();
|
||||||
AssignIndices(structs_.vec);
|
AssignIndices(structs_.vec);
|
||||||
@@ -3918,32 +3958,52 @@ bool EnumDef::Deserialize(Parser &parser, const reflection::Enum *_enum) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Offset<reflection::EnumVal> EnumVal::Serialize(FlatBufferBuilder *builder,
|
flatbuffers::Offset<
|
||||||
const Parser &parser) const {
|
flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>>
|
||||||
auto name__ = builder->CreateString(name);
|
EnumVal::SerializeAttributes(FlatBufferBuilder *builder,
|
||||||
auto type__ = union_type.Serialize(builder);
|
const Parser &parser) const {
|
||||||
auto docs__ = parser.opts.binary_schema_comments
|
return SerializeAttributesCommon(attributes, builder, parser);
|
||||||
? builder->CreateVectorOfStrings(doc_comment)
|
|
||||||
: 0;
|
|
||||||
return reflection::CreateEnumVal(*builder, name__, value, type__, docs__);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EnumVal::Deserialize(const Parser &parser,
|
bool EnumVal::DeserializeAttributes(
|
||||||
const reflection::EnumVal *val) {
|
Parser &parser, const Vector<Offset<reflection::KeyValue>> *attrs) {
|
||||||
|
return DeserializeAttributesCommon(attributes, parser, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
Offset<reflection::EnumVal> EnumVal::Serialize(FlatBufferBuilder *builder,
|
||||||
|
const Parser &parser) const {
|
||||||
|
const auto name__ = builder->CreateString(name);
|
||||||
|
const auto type__ = union_type.Serialize(builder);
|
||||||
|
const auto attr__ = SerializeAttributes(builder, parser);
|
||||||
|
const auto docs__ = parser.opts.binary_schema_comments
|
||||||
|
? builder->CreateVectorOfStrings(doc_comment)
|
||||||
|
: 0;
|
||||||
|
return reflection::CreateEnumVal(*builder, name__, value, type__, docs__,
|
||||||
|
attr__);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EnumVal::Deserialize(Parser &parser, const reflection::EnumVal *val) {
|
||||||
name = val->name()->str();
|
name = val->name()->str();
|
||||||
value = val->value();
|
value = val->value();
|
||||||
if (!union_type.Deserialize(parser, val->union_type())) return false;
|
if (!union_type.Deserialize(parser, val->union_type())) return false;
|
||||||
|
if (!DeserializeAttributes(parser, val->attributes())) return false;
|
||||||
DeserializeDoc(doc_comment, val->documentation());
|
DeserializeDoc(doc_comment, val->documentation());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Offset<reflection::Type> Type::Serialize(FlatBufferBuilder *builder) const {
|
Offset<reflection::Type> Type::Serialize(FlatBufferBuilder *builder) const {
|
||||||
|
size_t element_size = SizeOf(element);
|
||||||
|
if (base_type == BASE_TYPE_VECTOR && element == BASE_TYPE_STRUCT &&
|
||||||
|
struct_def->bytesize != 0) {
|
||||||
|
// struct_def->bytesize==0 means struct is table
|
||||||
|
element_size = struct_def->bytesize;
|
||||||
|
}
|
||||||
return reflection::CreateType(
|
return reflection::CreateType(
|
||||||
*builder, static_cast<reflection::BaseType>(base_type),
|
*builder, static_cast<reflection::BaseType>(base_type),
|
||||||
static_cast<reflection::BaseType>(element),
|
static_cast<reflection::BaseType>(element),
|
||||||
struct_def ? struct_def->index : (enum_def ? enum_def->index : -1),
|
struct_def ? struct_def->index : (enum_def ? enum_def->index : -1),
|
||||||
fixed_length, static_cast<uint32_t>(SizeOf(base_type)),
|
fixed_length, static_cast<uint32_t>(SizeOf(base_type)),
|
||||||
static_cast<uint32_t>(SizeOf(element)));
|
static_cast<uint32_t>(element_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Type::Deserialize(const Parser &parser, const reflection::Type *type) {
|
bool Type::Deserialize(const Parser &parser, const reflection::Type *type) {
|
||||||
@@ -3977,37 +4037,12 @@ flatbuffers::Offset<
|
|||||||
flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>>
|
flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>>
|
||||||
Definition::SerializeAttributes(FlatBufferBuilder *builder,
|
Definition::SerializeAttributes(FlatBufferBuilder *builder,
|
||||||
const Parser &parser) const {
|
const Parser &parser) const {
|
||||||
std::vector<flatbuffers::Offset<reflection::KeyValue>> attrs;
|
return SerializeAttributesCommon(attributes, builder, parser);
|
||||||
for (auto kv = attributes.dict.begin(); kv != attributes.dict.end(); ++kv) {
|
|
||||||
auto it = parser.known_attributes_.find(kv->first);
|
|
||||||
FLATBUFFERS_ASSERT(it != parser.known_attributes_.end());
|
|
||||||
if (parser.opts.binary_schema_builtins || !it->second) {
|
|
||||||
auto key = builder->CreateString(kv->first);
|
|
||||||
auto val = builder->CreateString(kv->second->constant);
|
|
||||||
attrs.push_back(reflection::CreateKeyValue(*builder, key, val));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (attrs.size()) {
|
|
||||||
return builder->CreateVectorOfSortedTables(&attrs);
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Definition::DeserializeAttributes(
|
bool Definition::DeserializeAttributes(
|
||||||
Parser &parser, const Vector<Offset<reflection::KeyValue>> *attrs) {
|
Parser &parser, const Vector<Offset<reflection::KeyValue>> *attrs) {
|
||||||
if (attrs == nullptr) return true;
|
return DeserializeAttributesCommon(attributes, parser, attrs);
|
||||||
for (uoffset_t i = 0; i < attrs->size(); ++i) {
|
|
||||||
auto kv = attrs->Get(i);
|
|
||||||
auto value = new Value();
|
|
||||||
if (kv->value()) { value->constant = kv->value()->str(); }
|
|
||||||
if (attributes.Add(kv->key()->str(), value)) {
|
|
||||||
delete value;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
parser.known_attributes_[kv->key()->str()];
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
@@ -4122,7 +4157,7 @@ std::string Parser::ConformTo(const Parser &base) {
|
|||||||
struct_def.defined_namespace->GetFullyQualifiedName(struct_def.name);
|
struct_def.defined_namespace->GetFullyQualifiedName(struct_def.name);
|
||||||
auto struct_def_base = base.LookupStruct(qualified_name);
|
auto struct_def_base = base.LookupStruct(qualified_name);
|
||||||
if (!struct_def_base) continue;
|
if (!struct_def_base) continue;
|
||||||
std::set<FieldDef*> renamed_fields;
|
std::set<FieldDef *> renamed_fields;
|
||||||
for (auto fit = struct_def.fields.vec.begin();
|
for (auto fit = struct_def.fields.vec.begin();
|
||||||
fit != struct_def.fields.vec.end(); ++fit) {
|
fit != struct_def.fields.vec.end(); ++fit) {
|
||||||
auto &field = **fit;
|
auto &field = **fit;
|
||||||
@@ -4151,11 +4186,11 @@ std::string Parser::ConformTo(const Parser &base) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//deletion of trailing fields are not allowed
|
// deletion of trailing fields are not allowed
|
||||||
for (auto fit = struct_def_base->fields.vec.begin();
|
for (auto fit = struct_def_base->fields.vec.begin();
|
||||||
fit != struct_def_base->fields.vec.end(); ++fit ) {
|
fit != struct_def_base->fields.vec.end(); ++fit) {
|
||||||
auto &field_base = **fit;
|
auto &field_base = **fit;
|
||||||
//not a renamed field
|
// not a renamed field
|
||||||
if (renamed_fields.find(&field_base) == renamed_fields.end()) {
|
if (renamed_fields.find(&field_base) == renamed_fields.end()) {
|
||||||
auto field = struct_def.fields.Lookup(field_base.name);
|
auto field = struct_def.fields.Lookup(field_base.name);
|
||||||
if (!field) {
|
if (!field) {
|
||||||
|
|||||||
@@ -119,4 +119,4 @@ extension UInt64: Scalar, Verifiable {
|
|||||||
public typealias NumericValue = UInt64
|
public typealias NumericValue = UInt64
|
||||||
}
|
}
|
||||||
|
|
||||||
public func FlatBuffersVersion_22_9_29() {}
|
public func FlatBuffersVersion_22_10_26() {}
|
||||||
|
|||||||
13
tests/Abc.nim
Normal file
13
tests/Abc.nim
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#[ Abc
|
||||||
|
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||||
|
Or modify. I'm a message, not a cop.
|
||||||
|
|
||||||
|
flatc version: 22.10.26
|
||||||
|
|
||||||
|
Declared by :
|
||||||
|
]#
|
||||||
|
|
||||||
|
type Abc*{.pure.} = enum
|
||||||
|
A = 0.int32,
|
||||||
|
B = 1.int32,
|
||||||
|
C = 2.int32,
|
||||||
@@ -9,7 +9,7 @@ import com.google.flatbuffers.*;
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class LongFloatEntry extends Table {
|
public final class LongFloatEntry extends Table {
|
||||||
public static void ValidateVersion() { Constants.FLATBUFFERS_22_9_29(); }
|
public static void ValidateVersion() { Constants.FLATBUFFERS_22_10_26(); }
|
||||||
public static LongFloatEntry getRootAsLongFloatEntry(ByteBuffer _bb) { return getRootAsLongFloatEntry(_bb, new LongFloatEntry()); }
|
public static LongFloatEntry getRootAsLongFloatEntry(ByteBuffer _bb) { return getRootAsLongFloatEntry(_bb, new LongFloatEntry()); }
|
||||||
public static LongFloatEntry getRootAsLongFloatEntry(ByteBuffer _bb, LongFloatEntry obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
public static LongFloatEntry getRootAsLongFloatEntry(ByteBuffer _bb, LongFloatEntry obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class LongFloatEntry : Table() {
|
|||||||
return (val_1 - val_2).sign
|
return (val_1 - val_2).sign
|
||||||
}
|
}
|
||||||
companion object {
|
companion object {
|
||||||
fun validateVersion() = Constants.FLATBUFFERS_22_9_29()
|
fun validateVersion() = Constants.FLATBUFFERS_22_10_26()
|
||||||
fun getRootAsLongFloatEntry(_bb: ByteBuffer): LongFloatEntry = getRootAsLongFloatEntry(_bb, LongFloatEntry())
|
fun getRootAsLongFloatEntry(_bb: ByteBuffer): LongFloatEntry = getRootAsLongFloatEntry(_bb, LongFloatEntry())
|
||||||
fun getRootAsLongFloatEntry(_bb: ByteBuffer, obj: LongFloatEntry): LongFloatEntry {
|
fun getRootAsLongFloatEntry(_bb: ByteBuffer, obj: LongFloatEntry): LongFloatEntry {
|
||||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import com.google.flatbuffers.*;
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class LongFloatMap extends Table {
|
public final class LongFloatMap extends Table {
|
||||||
public static void ValidateVersion() { Constants.FLATBUFFERS_22_9_29(); }
|
public static void ValidateVersion() { Constants.FLATBUFFERS_22_10_26(); }
|
||||||
public static LongFloatMap getRootAsLongFloatMap(ByteBuffer _bb) { return getRootAsLongFloatMap(_bb, new LongFloatMap()); }
|
public static LongFloatMap getRootAsLongFloatMap(ByteBuffer _bb) { return getRootAsLongFloatMap(_bb, new LongFloatMap()); }
|
||||||
public static LongFloatMap getRootAsLongFloatMap(ByteBuffer _bb, LongFloatMap obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
public static LongFloatMap getRootAsLongFloatMap(ByteBuffer _bb, LongFloatMap obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class LongFloatMap : Table() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
companion object {
|
companion object {
|
||||||
fun validateVersion() = Constants.FLATBUFFERS_22_9_29()
|
fun validateVersion() = Constants.FLATBUFFERS_22_10_26()
|
||||||
fun getRootAsLongFloatMap(_bb: ByteBuffer): LongFloatMap = getRootAsLongFloatMap(_bb, LongFloatMap())
|
fun getRootAsLongFloatMap(_bb: ByteBuffer): LongFloatMap = getRootAsLongFloatMap(_bb, LongFloatMap())
|
||||||
fun getRootAsLongFloatMap(_bb: ByteBuffer, obj: LongFloatMap): LongFloatMap {
|
fun getRootAsLongFloatMap(_bb: ByteBuffer, obj: LongFloatMap): LongFloatMap {
|
||||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public struct KeywordsInTable : IFlatbufferObject
|
|||||||
{
|
{
|
||||||
private Table __p;
|
private Table __p;
|
||||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_22_9_29(); }
|
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_22_10_26(); }
|
||||||
public static KeywordsInTable GetRootAsKeywordsInTable(ByteBuffer _bb) { return GetRootAsKeywordsInTable(_bb, new KeywordsInTable()); }
|
public static KeywordsInTable GetRootAsKeywordsInTable(ByteBuffer _bb) { return GetRootAsKeywordsInTable(_bb, new KeywordsInTable()); }
|
||||||
public static KeywordsInTable GetRootAsKeywordsInTable(ByteBuffer _bb, KeywordsInTable obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
public static KeywordsInTable GetRootAsKeywordsInTable(ByteBuffer _bb, KeywordsInTable obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
||||||
public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); }
|
public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); }
|
||||||
|
|||||||
103
tests/MoreDefaults.nim
Normal file
103
tests/MoreDefaults.nim
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
#[ MoreDefaults
|
||||||
|
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||||
|
Or modify. I'm a message, not a cop.
|
||||||
|
|
||||||
|
flatc version: 22.10.26
|
||||||
|
|
||||||
|
Declared by :
|
||||||
|
]#
|
||||||
|
|
||||||
|
import Abc as Abc
|
||||||
|
import flatbuffers
|
||||||
|
|
||||||
|
type MoreDefaults* = object of FlatObj
|
||||||
|
func intsLength*(self: MoreDefaults): int =
|
||||||
|
let o = self.tab.Offset(4)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func ints*(self: MoreDefaults, j: int): int32 =
|
||||||
|
let o = self.tab.Offset(4)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 4.uoffset
|
||||||
|
return Get[int32](self.tab, x)
|
||||||
|
func ints*(self: MoreDefaults): seq[int32] =
|
||||||
|
let len = self.intsLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.ints(i))
|
||||||
|
func floatsLength*(self: MoreDefaults): int =
|
||||||
|
let o = self.tab.Offset(6)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func floats*(self: MoreDefaults, j: int): float32 =
|
||||||
|
let o = self.tab.Offset(6)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 4.uoffset
|
||||||
|
return Get[float32](self.tab, x)
|
||||||
|
func floats*(self: MoreDefaults): seq[float32] =
|
||||||
|
let len = self.floatsLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.floats(i))
|
||||||
|
func emptyString*(self: MoreDefaults): string =
|
||||||
|
let o = self.tab.Offset(8)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.String(self.tab.Pos + o)
|
||||||
|
return ""
|
||||||
|
func someString*(self: MoreDefaults): string =
|
||||||
|
let o = self.tab.Offset(10)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.String(self.tab.Pos + o)
|
||||||
|
return ""
|
||||||
|
func abcsLength*(self: MoreDefaults): int =
|
||||||
|
let o = self.tab.Offset(12)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func abcs*(self: MoreDefaults, j: int): Abc.Abc =
|
||||||
|
let o = self.tab.Offset(12)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 4.uoffset
|
||||||
|
return Abc.Abc(Get[int32](self.tab, x))
|
||||||
|
func abcs*(self: MoreDefaults): seq[Abc.Abc] =
|
||||||
|
let len = self.abcsLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.abcs(i))
|
||||||
|
func boolsLength*(self: MoreDefaults): int =
|
||||||
|
let o = self.tab.Offset(14)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func bools*(self: MoreDefaults, j: int): bool =
|
||||||
|
let o = self.tab.Offset(14)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 1.uoffset
|
||||||
|
return Get[bool](self.tab, x)
|
||||||
|
func bools*(self: MoreDefaults): seq[bool] =
|
||||||
|
let len = self.boolsLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.bools(i))
|
||||||
|
proc MoreDefaultsStart*(builder: var Builder) =
|
||||||
|
builder.StartObject(6)
|
||||||
|
proc MoreDefaultsAddints*(builder: var Builder, ints: uoffset) =
|
||||||
|
builder.PrependSlot(0, ints, default(uoffset))
|
||||||
|
proc MoreDefaultsStartintsVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(4, numElems, 4)
|
||||||
|
proc MoreDefaultsAddfloats*(builder: var Builder, floats: uoffset) =
|
||||||
|
builder.PrependSlot(1, floats, default(uoffset))
|
||||||
|
proc MoreDefaultsStartfloatsVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(4, numElems, 4)
|
||||||
|
proc MoreDefaultsAddemptyString*(builder: var Builder, emptyString: uoffset) =
|
||||||
|
builder.PrependSlot(2, emptyString, default(uoffset))
|
||||||
|
proc MoreDefaultsAddsomeString*(builder: var Builder, someString: uoffset) =
|
||||||
|
builder.PrependSlot(3, someString, default(uoffset))
|
||||||
|
proc MoreDefaultsAddabcs*(builder: var Builder, abcs: uoffset) =
|
||||||
|
builder.PrependSlot(4, abcs, default(uoffset))
|
||||||
|
proc MoreDefaultsStartabcsVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(4, numElems, 4)
|
||||||
|
proc MoreDefaultsAddbools*(builder: var Builder, bools: uoffset) =
|
||||||
|
builder.PrependSlot(5, bools, default(uoffset))
|
||||||
|
proc MoreDefaultsStartboolsVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(1, numElems, 1)
|
||||||
|
proc MoreDefaultsEnd*(builder: var Builder): uoffset =
|
||||||
|
return builder.EndObject()
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||||
Or modify. I'm a message, not a cop.
|
Or modify. I'm a message, not a cop.
|
||||||
|
|
||||||
flatc version: 22.9.29
|
flatc version: 22.10.26
|
||||||
|
|
||||||
Declared by : //monster_test.fbs
|
Declared by : //monster_test.fbs
|
||||||
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
||||||
|
|||||||
26
tests/MyGame/Example/Ability.nim
Normal file
26
tests/MyGame/Example/Ability.nim
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#[ MyGame.Example.Ability
|
||||||
|
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||||
|
Or modify. I'm a message, not a cop.
|
||||||
|
|
||||||
|
flatc version: 22.10.26
|
||||||
|
|
||||||
|
Declared by :
|
||||||
|
Rooting type : MyGame.Example.Monster ()
|
||||||
|
]#
|
||||||
|
|
||||||
|
import flatbuffers
|
||||||
|
|
||||||
|
type Ability* = object of FlatObj
|
||||||
|
func id*(self: Ability): uint32 =
|
||||||
|
return Get[uint32](self.tab, self.tab.Pos + 0)
|
||||||
|
func `id=`*(self: var Ability, n: uint32): bool =
|
||||||
|
return self.tab.Mutate(self.tab.Pos + 0, n)
|
||||||
|
func distance*(self: Ability): uint32 =
|
||||||
|
return Get[uint32](self.tab, self.tab.Pos + 4)
|
||||||
|
func `distance=`*(self: var Ability, n: uint32): bool =
|
||||||
|
return self.tab.Mutate(self.tab.Pos + 4, n)
|
||||||
|
proc AbilityCreate*(self: var Builder, id: uint32, distance: uint32): uoffset =
|
||||||
|
self.Prep(4, 8)
|
||||||
|
self.Prepend(distance)
|
||||||
|
self.Prepend(id)
|
||||||
|
return self.Offset()
|
||||||
@@ -38,11 +38,15 @@ class AbilityT(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def InitFromBuf(cls, buf, pos):
|
def InitFromBuf(cls, buf, pos):
|
||||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
|
||||||
ability = Ability()
|
ability = Ability()
|
||||||
ability.Init(buf, pos+n)
|
ability.Init(buf, pos)
|
||||||
return cls.InitFromObj(ability)
|
return cls.InitFromObj(ability)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def InitFromPackedBuf(cls, buf, pos=0):
|
||||||
|
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)
|
||||||
|
return cls.InitFromBuf(buf, pos+n)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def InitFromObj(cls, ability):
|
def InitFromObj(cls, ability):
|
||||||
x = AbilityT()
|
x = AbilityT()
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||||
Or modify. I'm a message, not a cop.
|
Or modify. I'm a message, not a cop.
|
||||||
|
|
||||||
flatc version: 22.9.29
|
flatc version: 22.10.26
|
||||||
|
|
||||||
Declared by : //monster_test.fbs
|
Declared by : //monster_test.fbs
|
||||||
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
||||||
|
|||||||
15
tests/MyGame/Example/Any.nim
Normal file
15
tests/MyGame/Example/Any.nim
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#[ MyGame.Example.Any
|
||||||
|
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||||
|
Or modify. I'm a message, not a cop.
|
||||||
|
|
||||||
|
flatc version: 22.10.26
|
||||||
|
|
||||||
|
Declared by :
|
||||||
|
Rooting type : MyGame.Example.Monster ()
|
||||||
|
]#
|
||||||
|
|
||||||
|
type Any*{.pure.} = enum
|
||||||
|
None = 0.uint8,
|
||||||
|
Monster = 1.uint8,
|
||||||
|
TestSimpleTableWithEnum = 2.uint8,
|
||||||
|
MyGameExample2Monster = 3.uint8,
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||||
Or modify. I'm a message, not a cop.
|
Or modify. I'm a message, not a cop.
|
||||||
|
|
||||||
flatc version: 22.9.29
|
flatc version: 22.10.26
|
||||||
|
|
||||||
Declared by : //monster_test.fbs
|
Declared by : //monster_test.fbs
|
||||||
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
||||||
|
|||||||
15
tests/MyGame/Example/AnyAmbiguousAliases.nim
Normal file
15
tests/MyGame/Example/AnyAmbiguousAliases.nim
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#[ MyGame.Example.AnyAmbiguousAliases
|
||||||
|
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||||
|
Or modify. I'm a message, not a cop.
|
||||||
|
|
||||||
|
flatc version: 22.10.26
|
||||||
|
|
||||||
|
Declared by :
|
||||||
|
Rooting type : MyGame.Example.Monster ()
|
||||||
|
]#
|
||||||
|
|
||||||
|
type AnyAmbiguousAliases*{.pure.} = enum
|
||||||
|
None = 0.uint8,
|
||||||
|
M1 = 1.uint8,
|
||||||
|
M2 = 2.uint8,
|
||||||
|
M3 = 3.uint8,
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||||
Or modify. I'm a message, not a cop.
|
Or modify. I'm a message, not a cop.
|
||||||
|
|
||||||
flatc version: 22.9.29
|
flatc version: 22.10.26
|
||||||
|
|
||||||
Declared by : //monster_test.fbs
|
Declared by : //monster_test.fbs
|
||||||
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
||||||
|
|||||||
15
tests/MyGame/Example/AnyUniqueAliases.nim
Normal file
15
tests/MyGame/Example/AnyUniqueAliases.nim
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#[ MyGame.Example.AnyUniqueAliases
|
||||||
|
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||||
|
Or modify. I'm a message, not a cop.
|
||||||
|
|
||||||
|
flatc version: 22.10.26
|
||||||
|
|
||||||
|
Declared by :
|
||||||
|
Rooting type : MyGame.Example.Monster ()
|
||||||
|
]#
|
||||||
|
|
||||||
|
type AnyUniqueAliases*{.pure.} = enum
|
||||||
|
None = 0.uint8,
|
||||||
|
M = 1.uint8,
|
||||||
|
Ts = 2.uint8,
|
||||||
|
M2 = 3.uint8,
|
||||||
@@ -123,11 +123,15 @@ class ArrayStructT(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def InitFromBuf(cls, buf, pos):
|
def InitFromBuf(cls, buf, pos):
|
||||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
|
||||||
arrayStruct = ArrayStruct()
|
arrayStruct = ArrayStruct()
|
||||||
arrayStruct.Init(buf, pos+n)
|
arrayStruct.Init(buf, pos)
|
||||||
return cls.InitFromObj(arrayStruct)
|
return cls.InitFromObj(arrayStruct)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def InitFromPackedBuf(cls, buf, pos=0):
|
||||||
|
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)
|
||||||
|
return cls.InitFromBuf(buf, pos+n)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def InitFromObj(cls, arrayStruct):
|
def InitFromObj(cls, arrayStruct):
|
||||||
x = ArrayStructT()
|
x = ArrayStructT()
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public struct ArrayTable : IFlatbufferObject
|
|||||||
{
|
{
|
||||||
private Table __p;
|
private Table __p;
|
||||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_22_9_29(); }
|
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_22_10_26(); }
|
||||||
public static ArrayTable GetRootAsArrayTable(ByteBuffer _bb) { return GetRootAsArrayTable(_bb, new ArrayTable()); }
|
public static ArrayTable GetRootAsArrayTable(ByteBuffer _bb) { return GetRootAsArrayTable(_bb, new ArrayTable()); }
|
||||||
public static ArrayTable GetRootAsArrayTable(ByteBuffer _bb, ArrayTable obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
public static ArrayTable GetRootAsArrayTable(ByteBuffer _bb, ArrayTable obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
||||||
public static bool ArrayTableBufferHasIdentifier(ByteBuffer _bb) { return Table.__has_identifier(_bb, "ARRT"); }
|
public static bool ArrayTableBufferHasIdentifier(ByteBuffer _bb) { return Table.__has_identifier(_bb, "ARRT"); }
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import com.google.flatbuffers.*;
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class ArrayTable extends Table {
|
public final class ArrayTable extends Table {
|
||||||
public static void ValidateVersion() { Constants.FLATBUFFERS_22_9_29(); }
|
public static void ValidateVersion() { Constants.FLATBUFFERS_22_10_26(); }
|
||||||
public static ArrayTable getRootAsArrayTable(ByteBuffer _bb) { return getRootAsArrayTable(_bb, new ArrayTable()); }
|
public static ArrayTable getRootAsArrayTable(ByteBuffer _bb) { return getRootAsArrayTable(_bb, new ArrayTable()); }
|
||||||
public static ArrayTable getRootAsArrayTable(ByteBuffer _bb, ArrayTable obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
public static ArrayTable getRootAsArrayTable(ByteBuffer _bb, ArrayTable obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||||
public static boolean ArrayTableBufferHasIdentifier(ByteBuffer _bb) { return __has_identifier(_bb, "ARRT"); }
|
public static boolean ArrayTableBufferHasIdentifier(ByteBuffer _bb) { return __has_identifier(_bb, "ARRT"); }
|
||||||
|
|||||||
@@ -62,11 +62,15 @@ class ArrayTableT(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def InitFromBuf(cls, buf, pos):
|
def InitFromBuf(cls, buf, pos):
|
||||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
|
||||||
arrayTable = ArrayTable()
|
arrayTable = ArrayTable()
|
||||||
arrayTable.Init(buf, pos+n)
|
arrayTable.Init(buf, pos)
|
||||||
return cls.InitFromObj(arrayTable)
|
return cls.InitFromObj(arrayTable)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def InitFromPackedBuf(cls, buf, pos=0):
|
||||||
|
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)
|
||||||
|
return cls.InitFromBuf(buf, pos+n)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def InitFromObj(cls, arrayTable):
|
def InitFromObj(cls, arrayTable):
|
||||||
x = ArrayTableT()
|
x = ArrayTableT()
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||||
Or modify. I'm a message, not a cop.
|
Or modify. I'm a message, not a cop.
|
||||||
|
|
||||||
flatc version: 22.9.29
|
flatc version: 22.10.26
|
||||||
|
|
||||||
Declared by : //monster_test.fbs
|
Declared by : //monster_test.fbs
|
||||||
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
||||||
|
|||||||
18
tests/MyGame/Example/Color.nim
Normal file
18
tests/MyGame/Example/Color.nim
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#[ MyGame.Example.Color
|
||||||
|
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||||
|
Or modify. I'm a message, not a cop.
|
||||||
|
|
||||||
|
flatc version: 22.10.26
|
||||||
|
|
||||||
|
Declared by :
|
||||||
|
Rooting type : MyGame.Example.Monster ()
|
||||||
|
]#
|
||||||
|
|
||||||
|
# Composite components of Monster color.
|
||||||
|
type Color*{.pure.} = enum
|
||||||
|
Red = 1.uint8,
|
||||||
|
# \brief color Green
|
||||||
|
# Green is bit_flag with value (1u << 1)
|
||||||
|
Green = 2.uint8,
|
||||||
|
# \brief color Blue (1u << 3)
|
||||||
|
Blue = 8.uint8,
|
||||||
@@ -5,8 +5,8 @@ package MyGame.Example;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class LongEnum {
|
public final class LongEnum {
|
||||||
private LongEnum() { }
|
private LongEnum() { }
|
||||||
public static final long LongOne = 2;
|
public static final long LongOne = 2L;
|
||||||
public static final long LongTwo = 4;
|
public static final long LongTwo = 4L;
|
||||||
public static final long LongBig = 1099511627776;
|
public static final long LongBig = 1099511627776L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||||
Or modify. I'm a message, not a cop.
|
Or modify. I'm a message, not a cop.
|
||||||
|
|
||||||
flatc version: 22.9.29
|
flatc version: 22.10.26
|
||||||
|
|
||||||
Declared by : //monster_test.fbs
|
Declared by : //monster_test.fbs
|
||||||
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
||||||
|
|||||||
14
tests/MyGame/Example/LongEnum.nim
Normal file
14
tests/MyGame/Example/LongEnum.nim
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#[ MyGame.Example.LongEnum
|
||||||
|
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||||
|
Or modify. I'm a message, not a cop.
|
||||||
|
|
||||||
|
flatc version: 22.10.26
|
||||||
|
|
||||||
|
Declared by :
|
||||||
|
Rooting type : MyGame.Example.Monster ()
|
||||||
|
]#
|
||||||
|
|
||||||
|
type LongEnum*{.pure.} = enum
|
||||||
|
LongOne = 2.uint64,
|
||||||
|
LongTwo = 4.uint64,
|
||||||
|
LongBig = 1099511627776.uint64,
|
||||||
@@ -14,7 +14,7 @@ public struct Monster : IFlatbufferObject
|
|||||||
{
|
{
|
||||||
private Table __p;
|
private Table __p;
|
||||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_22_9_29(); }
|
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_22_10_26(); }
|
||||||
public static Monster GetRootAsMonster(ByteBuffer _bb) { return GetRootAsMonster(_bb, new Monster()); }
|
public static Monster GetRootAsMonster(ByteBuffer _bb) { return GetRootAsMonster(_bb, new Monster()); }
|
||||||
public static Monster GetRootAsMonster(ByteBuffer _bb, Monster obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
public static Monster GetRootAsMonster(ByteBuffer _bb, Monster obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
||||||
public static bool MonsterBufferHasIdentifier(ByteBuffer _bb) { return Table.__has_identifier(_bb, "MONS"); }
|
public static bool MonsterBufferHasIdentifier(ByteBuffer _bb) { return Table.__has_identifier(_bb, "MONS"); }
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import com.google.flatbuffers.*;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class Monster extends Table {
|
public final class Monster extends Table {
|
||||||
public static void ValidateVersion() { Constants.FLATBUFFERS_22_9_29(); }
|
public static void ValidateVersion() { Constants.FLATBUFFERS_22_10_26(); }
|
||||||
public static Monster getRootAsMonster(ByteBuffer _bb) { return getRootAsMonster(_bb, new Monster()); }
|
public static Monster getRootAsMonster(ByteBuffer _bb) { return getRootAsMonster(_bb, new Monster()); }
|
||||||
public static Monster getRootAsMonster(ByteBuffer _bb, Monster obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
public static Monster getRootAsMonster(ByteBuffer _bb, Monster obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||||
public static boolean MonsterBufferHasIdentifier(ByteBuffer _bb) { return __has_identifier(_bb, "MONS"); }
|
public static boolean MonsterBufferHasIdentifier(ByteBuffer _bb) { return __has_identifier(_bb, "MONS"); }
|
||||||
|
|||||||
@@ -874,7 +874,7 @@ class Monster : Table() {
|
|||||||
return compareStrings(__offset(10, o1, _bb), __offset(10, o2, _bb), _bb)
|
return compareStrings(__offset(10, o1, _bb), __offset(10, o2, _bb), _bb)
|
||||||
}
|
}
|
||||||
companion object {
|
companion object {
|
||||||
fun validateVersion() = Constants.FLATBUFFERS_22_9_29()
|
fun validateVersion() = Constants.FLATBUFFERS_22_10_26()
|
||||||
fun getRootAsMonster(_bb: ByteBuffer): Monster = getRootAsMonster(_bb, Monster())
|
fun getRootAsMonster(_bb: ByteBuffer): Monster = getRootAsMonster(_bb, Monster())
|
||||||
fun getRootAsMonster(_bb: ByteBuffer, obj: Monster): Monster {
|
fun getRootAsMonster(_bb: ByteBuffer, obj: Monster): Monster {
|
||||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||||
Or modify. I'm a message, not a cop.
|
Or modify. I'm a message, not a cop.
|
||||||
|
|
||||||
flatc version: 22.9.29
|
flatc version: 22.10.26
|
||||||
|
|
||||||
Declared by : //monster_test.fbs
|
Declared by : //monster_test.fbs
|
||||||
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
|
||||||
@@ -359,7 +359,7 @@ function mt:Testarrayofsortedstruct(j)
|
|||||||
local o = self.view:Offset(62)
|
local o = self.view:Offset(62)
|
||||||
if o ~= 0 then
|
if o ~= 0 then
|
||||||
local x = self.view:Vector(o)
|
local x = self.view:Vector(o)
|
||||||
x = x + ((j-1) * 4)
|
x = x + ((j-1) * 8)
|
||||||
local obj = __MyGame_Example_Ability.New()
|
local obj = __MyGame_Example_Ability.New()
|
||||||
obj:Init(self.view.bytes, x)
|
obj:Init(self.view.bytes, x)
|
||||||
return obj
|
return obj
|
||||||
@@ -852,7 +852,7 @@ function Monster.AddTestarrayofsortedstruct(builder, testarrayofsortedstruct)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Monster.StartTestarrayofsortedstructVector(builder, numElems)
|
function Monster.StartTestarrayofsortedstructVector(builder, numElems)
|
||||||
return builder:StartVector(4, numElems, 4)
|
return builder:StartVector(8, numElems, 4)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Monster.AddFlex(builder, flex)
|
function Monster.AddFlex(builder, flex)
|
||||||
|
|||||||
662
tests/MyGame/Example/Monster.nim
Normal file
662
tests/MyGame/Example/Monster.nim
Normal file
@@ -0,0 +1,662 @@
|
|||||||
|
#[ MyGame.Example.Monster
|
||||||
|
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||||
|
Or modify. I'm a message, not a cop.
|
||||||
|
|
||||||
|
flatc version: 22.10.26
|
||||||
|
|
||||||
|
Declared by :
|
||||||
|
Rooting type : MyGame.Example.Monster ()
|
||||||
|
]#
|
||||||
|
|
||||||
|
import ../InParentNamespace as MyGame_InParentNamespace
|
||||||
|
import Ability as MyGame_Example_Ability
|
||||||
|
import Any as MyGame_Example_Any
|
||||||
|
import AnyAmbiguousAliases as MyGame_Example_AnyAmbiguousAliases
|
||||||
|
import AnyUniqueAliases as MyGame_Example_AnyUniqueAliases
|
||||||
|
import Color as MyGame_Example_Color
|
||||||
|
import LongEnum as MyGame_Example_LongEnum
|
||||||
|
import Race as MyGame_Example_Race
|
||||||
|
import Referrable as MyGame_Example_Referrable
|
||||||
|
import Stat as MyGame_Example_Stat
|
||||||
|
import Test as MyGame_Example_Test
|
||||||
|
import Vec3 as MyGame_Example_Vec3
|
||||||
|
import flatbuffers
|
||||||
|
import std/options
|
||||||
|
|
||||||
|
# an example documentation comment: "monster object"
|
||||||
|
type Monster* = object of FlatObj
|
||||||
|
func pos*(self: Monster): Option[MyGame_Example_Vec3.Vec3] =
|
||||||
|
let o = self.tab.Offset(4)
|
||||||
|
if o != 0:
|
||||||
|
return some(MyGame_Example_Vec3.Vec3(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + o)))
|
||||||
|
func mana*(self: Monster): int16 =
|
||||||
|
let o = self.tab.Offset(6)
|
||||||
|
if o != 0:
|
||||||
|
return Get[int16](self.tab, self.tab.Pos + o)
|
||||||
|
return 150
|
||||||
|
func `mana=`*(self: var Monster, n: int16): bool =
|
||||||
|
return self.tab.MutateSlot(6, n)
|
||||||
|
func hp*(self: Monster): int16 =
|
||||||
|
let o = self.tab.Offset(8)
|
||||||
|
if o != 0:
|
||||||
|
return Get[int16](self.tab, self.tab.Pos + o)
|
||||||
|
return 100
|
||||||
|
func `hp=`*(self: var Monster, n: int16): bool =
|
||||||
|
return self.tab.MutateSlot(8, n)
|
||||||
|
func name*(self: Monster): string =
|
||||||
|
let o = self.tab.Offset(10)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.String(self.tab.Pos + o)
|
||||||
|
return ""
|
||||||
|
func inventoryLength*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(14)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func inventory*(self: Monster, j: int): uint8 =
|
||||||
|
let o = self.tab.Offset(14)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 1.uoffset
|
||||||
|
return Get[uint8](self.tab, x)
|
||||||
|
func inventory*(self: Monster): seq[uint8] =
|
||||||
|
let len = self.inventoryLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.inventory(i))
|
||||||
|
func color*(self: Monster): MyGame_Example_Color.Color =
|
||||||
|
let o = self.tab.Offset(16)
|
||||||
|
if o != 0:
|
||||||
|
return MyGame_Example_Color.Color(Get[uint8](self.tab, self.tab.Pos + o))
|
||||||
|
return type(result)(8)
|
||||||
|
func `color=`*(self: var Monster, n: MyGame_Example_Color.Color): bool =
|
||||||
|
return self.tab.MutateSlot(16, n)
|
||||||
|
func testType*(self: Monster): MyGame_Example_Any.Any =
|
||||||
|
let o = self.tab.Offset(18)
|
||||||
|
if o != 0:
|
||||||
|
return MyGame_Example_Any.Any(Get[uint8](self.tab, self.tab.Pos + o))
|
||||||
|
return type(result)(0)
|
||||||
|
func `testType=`*(self: var Monster, n: MyGame_Example_Any.Any): bool =
|
||||||
|
return self.tab.MutateSlot(18, n)
|
||||||
|
func test*(self: Monster): Option[Vtable] =
|
||||||
|
let o = self.tab.Offset(20)
|
||||||
|
if o != 0:
|
||||||
|
return some(self.tab.Union(o))
|
||||||
|
func test4Length*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(22)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func test4*(self: Monster, j: int): MyGame_Example_Test.Test =
|
||||||
|
let o = self.tab.Offset(22)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 4.uoffset
|
||||||
|
return MyGame_Example_Test.Test(tab: Vtable(Bytes: self.tab.Bytes, Pos: x))
|
||||||
|
func test4*(self: Monster): seq[MyGame_Example_Test.Test] =
|
||||||
|
let len = self.test4Length
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.test4(i))
|
||||||
|
func testarrayofstringLength*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(24)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func testarrayofstring*(self: Monster, j: int): string =
|
||||||
|
let o = self.tab.Offset(24)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 4.uoffset
|
||||||
|
return self.tab.String(x)
|
||||||
|
func testarrayofstring*(self: Monster): seq[string] =
|
||||||
|
let len = self.testarrayofstringLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.testarrayofstring(i))
|
||||||
|
func testarrayoftablesLength*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(26)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func testarrayoftables*(self: Monster, j: int): Monster =
|
||||||
|
let o = self.tab.Offset(26)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 4.uoffset
|
||||||
|
return Monster(tab: Vtable(Bytes: self.tab.Bytes, Pos: x))
|
||||||
|
func testarrayoftables*(self: Monster): seq[Monster] =
|
||||||
|
let len = self.testarrayoftablesLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.testarrayoftables(i))
|
||||||
|
func enemy*(self: Monster): Option[Monster] =
|
||||||
|
let o = self.tab.Offset(28)
|
||||||
|
if o != 0:
|
||||||
|
return some(Monster(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + o)))
|
||||||
|
func testnestedflatbufferLength*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(30)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func testnestedflatbuffer*(self: Monster, j: int): uint8 =
|
||||||
|
let o = self.tab.Offset(30)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 1.uoffset
|
||||||
|
return Get[uint8](self.tab, x)
|
||||||
|
func testnestedflatbuffer*(self: Monster): seq[uint8] =
|
||||||
|
let len = self.testnestedflatbufferLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.testnestedflatbuffer(i))
|
||||||
|
func testempty*(self: Monster): Option[MyGame_Example_Stat.Stat] =
|
||||||
|
let o = self.tab.Offset(32)
|
||||||
|
if o != 0:
|
||||||
|
return some(MyGame_Example_Stat.Stat(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + o)))
|
||||||
|
func testbool*(self: Monster): bool =
|
||||||
|
let o = self.tab.Offset(34)
|
||||||
|
if o != 0:
|
||||||
|
return Get[bool](self.tab, self.tab.Pos + o)
|
||||||
|
return false
|
||||||
|
func `testbool=`*(self: var Monster, n: bool): bool =
|
||||||
|
return self.tab.MutateSlot(34, n)
|
||||||
|
func testhashs32Fnv1*(self: Monster): int32 =
|
||||||
|
let o = self.tab.Offset(36)
|
||||||
|
if o != 0:
|
||||||
|
return Get[int32](self.tab, self.tab.Pos + o)
|
||||||
|
return 0
|
||||||
|
func `testhashs32Fnv1=`*(self: var Monster, n: int32): bool =
|
||||||
|
return self.tab.MutateSlot(36, n)
|
||||||
|
func testhashu32Fnv1*(self: Monster): uint32 =
|
||||||
|
let o = self.tab.Offset(38)
|
||||||
|
if o != 0:
|
||||||
|
return Get[uint32](self.tab, self.tab.Pos + o)
|
||||||
|
return 0
|
||||||
|
func `testhashu32Fnv1=`*(self: var Monster, n: uint32): bool =
|
||||||
|
return self.tab.MutateSlot(38, n)
|
||||||
|
func testhashs64Fnv1*(self: Monster): int64 =
|
||||||
|
let o = self.tab.Offset(40)
|
||||||
|
if o != 0:
|
||||||
|
return Get[int64](self.tab, self.tab.Pos + o)
|
||||||
|
return 0
|
||||||
|
func `testhashs64Fnv1=`*(self: var Monster, n: int64): bool =
|
||||||
|
return self.tab.MutateSlot(40, n)
|
||||||
|
func testhashu64Fnv1*(self: Monster): uint64 =
|
||||||
|
let o = self.tab.Offset(42)
|
||||||
|
if o != 0:
|
||||||
|
return Get[uint64](self.tab, self.tab.Pos + o)
|
||||||
|
return 0
|
||||||
|
func `testhashu64Fnv1=`*(self: var Monster, n: uint64): bool =
|
||||||
|
return self.tab.MutateSlot(42, n)
|
||||||
|
func testhashs32Fnv1a*(self: Monster): int32 =
|
||||||
|
let o = self.tab.Offset(44)
|
||||||
|
if o != 0:
|
||||||
|
return Get[int32](self.tab, self.tab.Pos + o)
|
||||||
|
return 0
|
||||||
|
func `testhashs32Fnv1a=`*(self: var Monster, n: int32): bool =
|
||||||
|
return self.tab.MutateSlot(44, n)
|
||||||
|
func testhashu32Fnv1a*(self: Monster): uint32 =
|
||||||
|
let o = self.tab.Offset(46)
|
||||||
|
if o != 0:
|
||||||
|
return Get[uint32](self.tab, self.tab.Pos + o)
|
||||||
|
return 0
|
||||||
|
func `testhashu32Fnv1a=`*(self: var Monster, n: uint32): bool =
|
||||||
|
return self.tab.MutateSlot(46, n)
|
||||||
|
func testhashs64Fnv1a*(self: Monster): int64 =
|
||||||
|
let o = self.tab.Offset(48)
|
||||||
|
if o != 0:
|
||||||
|
return Get[int64](self.tab, self.tab.Pos + o)
|
||||||
|
return 0
|
||||||
|
func `testhashs64Fnv1a=`*(self: var Monster, n: int64): bool =
|
||||||
|
return self.tab.MutateSlot(48, n)
|
||||||
|
func testhashu64Fnv1a*(self: Monster): uint64 =
|
||||||
|
let o = self.tab.Offset(50)
|
||||||
|
if o != 0:
|
||||||
|
return Get[uint64](self.tab, self.tab.Pos + o)
|
||||||
|
return 0
|
||||||
|
func `testhashu64Fnv1a=`*(self: var Monster, n: uint64): bool =
|
||||||
|
return self.tab.MutateSlot(50, n)
|
||||||
|
func testarrayofboolsLength*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(52)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func testarrayofbools*(self: Monster, j: int): bool =
|
||||||
|
let o = self.tab.Offset(52)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 1.uoffset
|
||||||
|
return Get[bool](self.tab, x)
|
||||||
|
func testarrayofbools*(self: Monster): seq[bool] =
|
||||||
|
let len = self.testarrayofboolsLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.testarrayofbools(i))
|
||||||
|
func testf*(self: Monster): float32 =
|
||||||
|
let o = self.tab.Offset(54)
|
||||||
|
if o != 0:
|
||||||
|
return Get[float32](self.tab, self.tab.Pos + o)
|
||||||
|
return 3.14159
|
||||||
|
func `testf=`*(self: var Monster, n: float32): bool =
|
||||||
|
return self.tab.MutateSlot(54, n)
|
||||||
|
func testf2*(self: Monster): float32 =
|
||||||
|
let o = self.tab.Offset(56)
|
||||||
|
if o != 0:
|
||||||
|
return Get[float32](self.tab, self.tab.Pos + o)
|
||||||
|
return 3.0
|
||||||
|
func `testf2=`*(self: var Monster, n: float32): bool =
|
||||||
|
return self.tab.MutateSlot(56, n)
|
||||||
|
func testf3*(self: Monster): float32 =
|
||||||
|
let o = self.tab.Offset(58)
|
||||||
|
if o != 0:
|
||||||
|
return Get[float32](self.tab, self.tab.Pos + o)
|
||||||
|
return 0.0
|
||||||
|
func `testf3=`*(self: var Monster, n: float32): bool =
|
||||||
|
return self.tab.MutateSlot(58, n)
|
||||||
|
func testarrayofstring2Length*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(60)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func testarrayofstring2*(self: Monster, j: int): string =
|
||||||
|
let o = self.tab.Offset(60)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 4.uoffset
|
||||||
|
return self.tab.String(x)
|
||||||
|
func testarrayofstring2*(self: Monster): seq[string] =
|
||||||
|
let len = self.testarrayofstring2Length
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.testarrayofstring2(i))
|
||||||
|
func testarrayofsortedstructLength*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(62)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func testarrayofsortedstruct*(self: Monster, j: int): MyGame_Example_Ability.Ability =
|
||||||
|
let o = self.tab.Offset(62)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 8.uoffset
|
||||||
|
return MyGame_Example_Ability.Ability(tab: Vtable(Bytes: self.tab.Bytes, Pos: x))
|
||||||
|
func testarrayofsortedstruct*(self: Monster): seq[MyGame_Example_Ability.Ability] =
|
||||||
|
let len = self.testarrayofsortedstructLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.testarrayofsortedstruct(i))
|
||||||
|
func flexLength*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(64)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func flex*(self: Monster, j: int): uint8 =
|
||||||
|
let o = self.tab.Offset(64)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 1.uoffset
|
||||||
|
return Get[uint8](self.tab, x)
|
||||||
|
func flex*(self: Monster): seq[uint8] =
|
||||||
|
let len = self.flexLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.flex(i))
|
||||||
|
func test5Length*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(66)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func test5*(self: Monster, j: int): MyGame_Example_Test.Test =
|
||||||
|
let o = self.tab.Offset(66)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 4.uoffset
|
||||||
|
return MyGame_Example_Test.Test(tab: Vtable(Bytes: self.tab.Bytes, Pos: x))
|
||||||
|
func test5*(self: Monster): seq[MyGame_Example_Test.Test] =
|
||||||
|
let len = self.test5Length
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.test5(i))
|
||||||
|
func vectorOfLongsLength*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(68)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func vectorOfLongs*(self: Monster, j: int): int64 =
|
||||||
|
let o = self.tab.Offset(68)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 8.uoffset
|
||||||
|
return Get[int64](self.tab, x)
|
||||||
|
func vectorOfLongs*(self: Monster): seq[int64] =
|
||||||
|
let len = self.vectorOfLongsLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.vectorOfLongs(i))
|
||||||
|
func vectorOfDoublesLength*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(70)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func vectorOfDoubles*(self: Monster, j: int): float64 =
|
||||||
|
let o = self.tab.Offset(70)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 8.uoffset
|
||||||
|
return Get[float64](self.tab, x)
|
||||||
|
func vectorOfDoubles*(self: Monster): seq[float64] =
|
||||||
|
let len = self.vectorOfDoublesLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.vectorOfDoubles(i))
|
||||||
|
func parentNamespaceTest*(self: Monster): Option[MyGame_InParentNamespace.InParentNamespace] =
|
||||||
|
let o = self.tab.Offset(72)
|
||||||
|
if o != 0:
|
||||||
|
return some(MyGame_InParentNamespace.InParentNamespace(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + o)))
|
||||||
|
func vectorOfReferrablesLength*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(74)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func vectorOfReferrables*(self: Monster, j: int): MyGame_Example_Referrable.Referrable =
|
||||||
|
let o = self.tab.Offset(74)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 4.uoffset
|
||||||
|
return MyGame_Example_Referrable.Referrable(tab: Vtable(Bytes: self.tab.Bytes, Pos: x))
|
||||||
|
func vectorOfReferrables*(self: Monster): seq[MyGame_Example_Referrable.Referrable] =
|
||||||
|
let len = self.vectorOfReferrablesLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.vectorOfReferrables(i))
|
||||||
|
func singleWeakReference*(self: Monster): uint64 =
|
||||||
|
let o = self.tab.Offset(76)
|
||||||
|
if o != 0:
|
||||||
|
return Get[uint64](self.tab, self.tab.Pos + o)
|
||||||
|
return 0
|
||||||
|
func `singleWeakReference=`*(self: var Monster, n: uint64): bool =
|
||||||
|
return self.tab.MutateSlot(76, n)
|
||||||
|
func vectorOfWeakReferencesLength*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(78)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func vectorOfWeakReferences*(self: Monster, j: int): uint64 =
|
||||||
|
let o = self.tab.Offset(78)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 8.uoffset
|
||||||
|
return Get[uint64](self.tab, x)
|
||||||
|
func vectorOfWeakReferences*(self: Monster): seq[uint64] =
|
||||||
|
let len = self.vectorOfWeakReferencesLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.vectorOfWeakReferences(i))
|
||||||
|
func vectorOfStrongReferrablesLength*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(80)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func vectorOfStrongReferrables*(self: Monster, j: int): MyGame_Example_Referrable.Referrable =
|
||||||
|
let o = self.tab.Offset(80)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 4.uoffset
|
||||||
|
return MyGame_Example_Referrable.Referrable(tab: Vtable(Bytes: self.tab.Bytes, Pos: x))
|
||||||
|
func vectorOfStrongReferrables*(self: Monster): seq[MyGame_Example_Referrable.Referrable] =
|
||||||
|
let len = self.vectorOfStrongReferrablesLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.vectorOfStrongReferrables(i))
|
||||||
|
func coOwningReference*(self: Monster): uint64 =
|
||||||
|
let o = self.tab.Offset(82)
|
||||||
|
if o != 0:
|
||||||
|
return Get[uint64](self.tab, self.tab.Pos + o)
|
||||||
|
return 0
|
||||||
|
func `coOwningReference=`*(self: var Monster, n: uint64): bool =
|
||||||
|
return self.tab.MutateSlot(82, n)
|
||||||
|
func vectorOfCoOwningReferencesLength*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(84)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func vectorOfCoOwningReferences*(self: Monster, j: int): uint64 =
|
||||||
|
let o = self.tab.Offset(84)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 8.uoffset
|
||||||
|
return Get[uint64](self.tab, x)
|
||||||
|
func vectorOfCoOwningReferences*(self: Monster): seq[uint64] =
|
||||||
|
let len = self.vectorOfCoOwningReferencesLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.vectorOfCoOwningReferences(i))
|
||||||
|
func nonOwningReference*(self: Monster): uint64 =
|
||||||
|
let o = self.tab.Offset(86)
|
||||||
|
if o != 0:
|
||||||
|
return Get[uint64](self.tab, self.tab.Pos + o)
|
||||||
|
return 0
|
||||||
|
func `nonOwningReference=`*(self: var Monster, n: uint64): bool =
|
||||||
|
return self.tab.MutateSlot(86, n)
|
||||||
|
func vectorOfNonOwningReferencesLength*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(88)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func vectorOfNonOwningReferences*(self: Monster, j: int): uint64 =
|
||||||
|
let o = self.tab.Offset(88)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 8.uoffset
|
||||||
|
return Get[uint64](self.tab, x)
|
||||||
|
func vectorOfNonOwningReferences*(self: Monster): seq[uint64] =
|
||||||
|
let len = self.vectorOfNonOwningReferencesLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.vectorOfNonOwningReferences(i))
|
||||||
|
func anyUniqueType*(self: Monster): MyGame_Example_AnyUniqueAliases.AnyUniqueAliases =
|
||||||
|
let o = self.tab.Offset(90)
|
||||||
|
if o != 0:
|
||||||
|
return MyGame_Example_AnyUniqueAliases.AnyUniqueAliases(Get[uint8](self.tab, self.tab.Pos + o))
|
||||||
|
return type(result)(0)
|
||||||
|
func `anyUniqueType=`*(self: var Monster, n: MyGame_Example_AnyUniqueAliases.AnyUniqueAliases): bool =
|
||||||
|
return self.tab.MutateSlot(90, n)
|
||||||
|
func anyUnique*(self: Monster): Option[Vtable] =
|
||||||
|
let o = self.tab.Offset(92)
|
||||||
|
if o != 0:
|
||||||
|
return some(self.tab.Union(o))
|
||||||
|
func anyAmbiguousType*(self: Monster): MyGame_Example_AnyAmbiguousAliases.AnyAmbiguousAliases =
|
||||||
|
let o = self.tab.Offset(94)
|
||||||
|
if o != 0:
|
||||||
|
return MyGame_Example_AnyAmbiguousAliases.AnyAmbiguousAliases(Get[uint8](self.tab, self.tab.Pos + o))
|
||||||
|
return type(result)(0)
|
||||||
|
func `anyAmbiguousType=`*(self: var Monster, n: MyGame_Example_AnyAmbiguousAliases.AnyAmbiguousAliases): bool =
|
||||||
|
return self.tab.MutateSlot(94, n)
|
||||||
|
func anyAmbiguous*(self: Monster): Option[Vtable] =
|
||||||
|
let o = self.tab.Offset(96)
|
||||||
|
if o != 0:
|
||||||
|
return some(self.tab.Union(o))
|
||||||
|
func vectorOfEnumsLength*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(98)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func vectorOfEnums*(self: Monster, j: int): MyGame_Example_Color.Color =
|
||||||
|
let o = self.tab.Offset(98)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 1.uoffset
|
||||||
|
return MyGame_Example_Color.Color(Get[uint8](self.tab, x))
|
||||||
|
func vectorOfEnums*(self: Monster): seq[MyGame_Example_Color.Color] =
|
||||||
|
let len = self.vectorOfEnumsLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.vectorOfEnums(i))
|
||||||
|
func signedEnum*(self: Monster): MyGame_Example_Race.Race =
|
||||||
|
let o = self.tab.Offset(100)
|
||||||
|
if o != 0:
|
||||||
|
return MyGame_Example_Race.Race(Get[int8](self.tab, self.tab.Pos + o))
|
||||||
|
return type(result)(-1)
|
||||||
|
func `signedEnum=`*(self: var Monster, n: MyGame_Example_Race.Race): bool =
|
||||||
|
return self.tab.MutateSlot(100, n)
|
||||||
|
func testrequirednestedflatbufferLength*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(102)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func testrequirednestedflatbuffer*(self: Monster, j: int): uint8 =
|
||||||
|
let o = self.tab.Offset(102)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 1.uoffset
|
||||||
|
return Get[uint8](self.tab, x)
|
||||||
|
func testrequirednestedflatbuffer*(self: Monster): seq[uint8] =
|
||||||
|
let len = self.testrequirednestedflatbufferLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.testrequirednestedflatbuffer(i))
|
||||||
|
func scalarKeySortedTablesLength*(self: Monster): int =
|
||||||
|
let o = self.tab.Offset(104)
|
||||||
|
if o != 0:
|
||||||
|
return self.tab.VectorLen(o)
|
||||||
|
func scalarKeySortedTables*(self: Monster, j: int): MyGame_Example_Stat.Stat =
|
||||||
|
let o = self.tab.Offset(104)
|
||||||
|
if o != 0:
|
||||||
|
var x = self.tab.Vector(o)
|
||||||
|
x += j.uoffset * 4.uoffset
|
||||||
|
return MyGame_Example_Stat.Stat(tab: Vtable(Bytes: self.tab.Bytes, Pos: x))
|
||||||
|
func scalarKeySortedTables*(self: Monster): seq[MyGame_Example_Stat.Stat] =
|
||||||
|
let len = self.scalarKeySortedTablesLength
|
||||||
|
for i in countup(0, len - 1):
|
||||||
|
result.add(self.scalarKeySortedTables(i))
|
||||||
|
func nativeInline*(self: Monster): Option[MyGame_Example_Test.Test] =
|
||||||
|
let o = self.tab.Offset(106)
|
||||||
|
if o != 0:
|
||||||
|
return some(MyGame_Example_Test.Test(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + o)))
|
||||||
|
func longEnumNonEnumDefault*(self: Monster): MyGame_Example_LongEnum.LongEnum =
|
||||||
|
let o = self.tab.Offset(108)
|
||||||
|
if o != 0:
|
||||||
|
return MyGame_Example_LongEnum.LongEnum(Get[uint64](self.tab, self.tab.Pos + o))
|
||||||
|
return type(result)(0)
|
||||||
|
func `longEnumNonEnumDefault=`*(self: var Monster, n: MyGame_Example_LongEnum.LongEnum): bool =
|
||||||
|
return self.tab.MutateSlot(108, n)
|
||||||
|
func longEnumNormalDefault*(self: Monster): MyGame_Example_LongEnum.LongEnum =
|
||||||
|
let o = self.tab.Offset(110)
|
||||||
|
if o != 0:
|
||||||
|
return MyGame_Example_LongEnum.LongEnum(Get[uint64](self.tab, self.tab.Pos + o))
|
||||||
|
return type(result)(2)
|
||||||
|
func `longEnumNormalDefault=`*(self: var Monster, n: MyGame_Example_LongEnum.LongEnum): bool =
|
||||||
|
return self.tab.MutateSlot(110, n)
|
||||||
|
proc MonsterStart*(builder: var Builder) =
|
||||||
|
builder.StartObject(54)
|
||||||
|
proc MonsterAddpos*(builder: var Builder, pos: uoffset) =
|
||||||
|
builder.PrependStructSlot(0, pos, default(uoffset))
|
||||||
|
proc MonsterAddmana*(builder: var Builder, mana: int16) =
|
||||||
|
builder.PrependSlot(1, mana, default(int16))
|
||||||
|
proc MonsterAddhp*(builder: var Builder, hp: int16) =
|
||||||
|
builder.PrependSlot(2, hp, default(int16))
|
||||||
|
proc MonsterAddname*(builder: var Builder, name: uoffset) =
|
||||||
|
builder.PrependSlot(3, name, default(uoffset))
|
||||||
|
proc MonsterAddinventory*(builder: var Builder, inventory: uoffset) =
|
||||||
|
builder.PrependSlot(5, inventory, default(uoffset))
|
||||||
|
proc MonsterStartinventoryVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(1, numElems, 1)
|
||||||
|
proc MonsterAddcolor*(builder: var Builder, color: uint8) =
|
||||||
|
builder.PrependSlot(6, color, default(uint8))
|
||||||
|
proc MonsterAddtestType*(builder: var Builder, testType: uint8) =
|
||||||
|
builder.PrependSlot(7, testType, default(uint8))
|
||||||
|
proc MonsterAddtest*(builder: var Builder, test: uoffset) =
|
||||||
|
builder.PrependSlot(8, test, default(uoffset))
|
||||||
|
proc MonsterAddtest4*(builder: var Builder, test4: uoffset) =
|
||||||
|
builder.PrependSlot(9, test4, default(uoffset))
|
||||||
|
proc MonsterStarttest4Vector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(4, numElems, 2)
|
||||||
|
proc MonsterAddtestarrayofstring*(builder: var Builder, testarrayofstring: uoffset) =
|
||||||
|
builder.PrependSlot(10, testarrayofstring, default(uoffset))
|
||||||
|
proc MonsterStarttestarrayofstringVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(4, numElems, 4)
|
||||||
|
proc MonsterAddtestarrayoftables*(builder: var Builder, testarrayoftables: uoffset) =
|
||||||
|
builder.PrependSlot(11, testarrayoftables, default(uoffset))
|
||||||
|
proc MonsterStarttestarrayoftablesVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(4, numElems, 4)
|
||||||
|
proc MonsterAddenemy*(builder: var Builder, enemy: uoffset) =
|
||||||
|
builder.PrependStructSlot(12, enemy, default(uoffset))
|
||||||
|
proc MonsterAddtestnestedflatbuffer*(builder: var Builder, testnestedflatbuffer: uoffset) =
|
||||||
|
builder.PrependSlot(13, testnestedflatbuffer, default(uoffset))
|
||||||
|
proc MonsterStarttestnestedflatbufferVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(1, numElems, 1)
|
||||||
|
proc MonsterAddtestempty*(builder: var Builder, testempty: uoffset) =
|
||||||
|
builder.PrependStructSlot(14, testempty, default(uoffset))
|
||||||
|
proc MonsterAddtestbool*(builder: var Builder, testbool: bool) =
|
||||||
|
builder.PrependSlot(15, testbool, default(bool))
|
||||||
|
proc MonsterAddtesthashs32Fnv1*(builder: var Builder, testhashs32Fnv1: int32) =
|
||||||
|
builder.PrependSlot(16, testhashs32Fnv1, default(int32))
|
||||||
|
proc MonsterAddtesthashu32Fnv1*(builder: var Builder, testhashu32Fnv1: uint32) =
|
||||||
|
builder.PrependSlot(17, testhashu32Fnv1, default(uint32))
|
||||||
|
proc MonsterAddtesthashs64Fnv1*(builder: var Builder, testhashs64Fnv1: int64) =
|
||||||
|
builder.PrependSlot(18, testhashs64Fnv1, default(int64))
|
||||||
|
proc MonsterAddtesthashu64Fnv1*(builder: var Builder, testhashu64Fnv1: uint64) =
|
||||||
|
builder.PrependSlot(19, testhashu64Fnv1, default(uint64))
|
||||||
|
proc MonsterAddtesthashs32Fnv1a*(builder: var Builder, testhashs32Fnv1a: int32) =
|
||||||
|
builder.PrependSlot(20, testhashs32Fnv1a, default(int32))
|
||||||
|
proc MonsterAddtesthashu32Fnv1a*(builder: var Builder, testhashu32Fnv1a: uint32) =
|
||||||
|
builder.PrependSlot(21, testhashu32Fnv1a, default(uint32))
|
||||||
|
proc MonsterAddtesthashs64Fnv1a*(builder: var Builder, testhashs64Fnv1a: int64) =
|
||||||
|
builder.PrependSlot(22, testhashs64Fnv1a, default(int64))
|
||||||
|
proc MonsterAddtesthashu64Fnv1a*(builder: var Builder, testhashu64Fnv1a: uint64) =
|
||||||
|
builder.PrependSlot(23, testhashu64Fnv1a, default(uint64))
|
||||||
|
proc MonsterAddtestarrayofbools*(builder: var Builder, testarrayofbools: uoffset) =
|
||||||
|
builder.PrependSlot(24, testarrayofbools, default(uoffset))
|
||||||
|
proc MonsterStarttestarrayofboolsVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(1, numElems, 1)
|
||||||
|
proc MonsterAddtestf*(builder: var Builder, testf: float32) =
|
||||||
|
builder.PrependSlot(25, testf, default(float32))
|
||||||
|
proc MonsterAddtestf2*(builder: var Builder, testf2: float32) =
|
||||||
|
builder.PrependSlot(26, testf2, default(float32))
|
||||||
|
proc MonsterAddtestf3*(builder: var Builder, testf3: float32) =
|
||||||
|
builder.PrependSlot(27, testf3, default(float32))
|
||||||
|
proc MonsterAddtestarrayofstring2*(builder: var Builder, testarrayofstring2: uoffset) =
|
||||||
|
builder.PrependSlot(28, testarrayofstring2, default(uoffset))
|
||||||
|
proc MonsterStarttestarrayofstring2Vector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(4, numElems, 4)
|
||||||
|
proc MonsterAddtestarrayofsortedstruct*(builder: var Builder, testarrayofsortedstruct: uoffset) =
|
||||||
|
builder.PrependSlot(29, testarrayofsortedstruct, default(uoffset))
|
||||||
|
proc MonsterStarttestarrayofsortedstructVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(8, numElems, 4)
|
||||||
|
proc MonsterAddflex*(builder: var Builder, flex: uoffset) =
|
||||||
|
builder.PrependSlot(30, flex, default(uoffset))
|
||||||
|
proc MonsterStartflexVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(1, numElems, 1)
|
||||||
|
proc MonsterAddtest5*(builder: var Builder, test5: uoffset) =
|
||||||
|
builder.PrependSlot(31, test5, default(uoffset))
|
||||||
|
proc MonsterStarttest5Vector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(4, numElems, 2)
|
||||||
|
proc MonsterAddvectorOfLongs*(builder: var Builder, vectorOfLongs: uoffset) =
|
||||||
|
builder.PrependSlot(32, vectorOfLongs, default(uoffset))
|
||||||
|
proc MonsterStartvectorOfLongsVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(8, numElems, 8)
|
||||||
|
proc MonsterAddvectorOfDoubles*(builder: var Builder, vectorOfDoubles: uoffset) =
|
||||||
|
builder.PrependSlot(33, vectorOfDoubles, default(uoffset))
|
||||||
|
proc MonsterStartvectorOfDoublesVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(8, numElems, 8)
|
||||||
|
proc MonsterAddparentNamespaceTest*(builder: var Builder, parentNamespaceTest: uoffset) =
|
||||||
|
builder.PrependStructSlot(34, parentNamespaceTest, default(uoffset))
|
||||||
|
proc MonsterAddvectorOfReferrables*(builder: var Builder, vectorOfReferrables: uoffset) =
|
||||||
|
builder.PrependSlot(35, vectorOfReferrables, default(uoffset))
|
||||||
|
proc MonsterStartvectorOfReferrablesVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(4, numElems, 4)
|
||||||
|
proc MonsterAddsingleWeakReference*(builder: var Builder, singleWeakReference: uint64) =
|
||||||
|
builder.PrependSlot(36, singleWeakReference, default(uint64))
|
||||||
|
proc MonsterAddvectorOfWeakReferences*(builder: var Builder, vectorOfWeakReferences: uoffset) =
|
||||||
|
builder.PrependSlot(37, vectorOfWeakReferences, default(uoffset))
|
||||||
|
proc MonsterStartvectorOfWeakReferencesVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(8, numElems, 8)
|
||||||
|
proc MonsterAddvectorOfStrongReferrables*(builder: var Builder, vectorOfStrongReferrables: uoffset) =
|
||||||
|
builder.PrependSlot(38, vectorOfStrongReferrables, default(uoffset))
|
||||||
|
proc MonsterStartvectorOfStrongReferrablesVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(4, numElems, 4)
|
||||||
|
proc MonsterAddcoOwningReference*(builder: var Builder, coOwningReference: uint64) =
|
||||||
|
builder.PrependSlot(39, coOwningReference, default(uint64))
|
||||||
|
proc MonsterAddvectorOfCoOwningReferences*(builder: var Builder, vectorOfCoOwningReferences: uoffset) =
|
||||||
|
builder.PrependSlot(40, vectorOfCoOwningReferences, default(uoffset))
|
||||||
|
proc MonsterStartvectorOfCoOwningReferencesVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(8, numElems, 8)
|
||||||
|
proc MonsterAddnonOwningReference*(builder: var Builder, nonOwningReference: uint64) =
|
||||||
|
builder.PrependSlot(41, nonOwningReference, default(uint64))
|
||||||
|
proc MonsterAddvectorOfNonOwningReferences*(builder: var Builder, vectorOfNonOwningReferences: uoffset) =
|
||||||
|
builder.PrependSlot(42, vectorOfNonOwningReferences, default(uoffset))
|
||||||
|
proc MonsterStartvectorOfNonOwningReferencesVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(8, numElems, 8)
|
||||||
|
proc MonsterAddanyUniqueType*(builder: var Builder, anyUniqueType: uint8) =
|
||||||
|
builder.PrependSlot(43, anyUniqueType, default(uint8))
|
||||||
|
proc MonsterAddanyUnique*(builder: var Builder, anyUnique: uoffset) =
|
||||||
|
builder.PrependSlot(44, anyUnique, default(uoffset))
|
||||||
|
proc MonsterAddanyAmbiguousType*(builder: var Builder, anyAmbiguousType: uint8) =
|
||||||
|
builder.PrependSlot(45, anyAmbiguousType, default(uint8))
|
||||||
|
proc MonsterAddanyAmbiguous*(builder: var Builder, anyAmbiguous: uoffset) =
|
||||||
|
builder.PrependSlot(46, anyAmbiguous, default(uoffset))
|
||||||
|
proc MonsterAddvectorOfEnums*(builder: var Builder, vectorOfEnums: uoffset) =
|
||||||
|
builder.PrependSlot(47, vectorOfEnums, default(uoffset))
|
||||||
|
proc MonsterStartvectorOfEnumsVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(1, numElems, 1)
|
||||||
|
proc MonsterAddsignedEnum*(builder: var Builder, signedEnum: int8) =
|
||||||
|
builder.PrependSlot(48, signedEnum, default(int8))
|
||||||
|
proc MonsterAddtestrequirednestedflatbuffer*(builder: var Builder, testrequirednestedflatbuffer: uoffset) =
|
||||||
|
builder.PrependSlot(49, testrequirednestedflatbuffer, default(uoffset))
|
||||||
|
proc MonsterStarttestrequirednestedflatbufferVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(1, numElems, 1)
|
||||||
|
proc MonsterAddscalarKeySortedTables*(builder: var Builder, scalarKeySortedTables: uoffset) =
|
||||||
|
builder.PrependSlot(50, scalarKeySortedTables, default(uoffset))
|
||||||
|
proc MonsterStartscalarKeySortedTablesVector*(builder: var Builder, numElems: uoffset) =
|
||||||
|
builder.StartVector(4, numElems, 4)
|
||||||
|
proc MonsterAddnativeInline*(builder: var Builder, nativeInline: uoffset) =
|
||||||
|
builder.PrependStructSlot(51, nativeInline, default(uoffset))
|
||||||
|
proc MonsterAddlongEnumNonEnumDefault*(builder: var Builder, longEnumNonEnumDefault: uint64) =
|
||||||
|
builder.PrependSlot(52, longEnumNonEnumDefault, default(uint64))
|
||||||
|
proc MonsterAddlongEnumNormalDefault*(builder: var Builder, longEnumNormalDefault: uint64) =
|
||||||
|
builder.PrependSlot(53, longEnumNormalDefault, default(uint64))
|
||||||
|
proc MonsterEnd*(builder: var Builder): uoffset =
|
||||||
|
return builder.EndObject()
|
||||||
@@ -1131,11 +1131,15 @@ class MonsterT(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def InitFromBuf(cls, buf, pos):
|
def InitFromBuf(cls, buf, pos):
|
||||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
|
||||||
monster = Monster()
|
monster = Monster()
|
||||||
monster.Init(buf, pos+n)
|
monster.Init(buf, pos)
|
||||||
return cls.InitFromObj(monster)
|
return cls.InitFromObj(monster)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def InitFromPackedBuf(cls, buf, pos=0):
|
||||||
|
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)
|
||||||
|
return cls.InitFromBuf(buf, pos+n)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def InitFromObj(cls, monster):
|
def InitFromObj(cls, monster):
|
||||||
x = MonsterT()
|
x = MonsterT()
|
||||||
|
|||||||
@@ -111,11 +111,15 @@ class NestedStructT(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def InitFromBuf(cls, buf, pos):
|
def InitFromBuf(cls, buf, pos):
|
||||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
|
||||||
nestedStruct = NestedStruct()
|
nestedStruct = NestedStruct()
|
||||||
nestedStruct.Init(buf, pos+n)
|
nestedStruct.Init(buf, pos)
|
||||||
return cls.InitFromObj(nestedStruct)
|
return cls.InitFromObj(nestedStruct)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def InitFromPackedBuf(cls, buf, pos=0):
|
||||||
|
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)
|
||||||
|
return cls.InitFromBuf(buf, pos+n)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def InitFromObj(cls, nestedStruct):
|
def InitFromObj(cls, nestedStruct):
|
||||||
x = NestedStructT()
|
x = NestedStructT()
|
||||||
|
|||||||
20
tests/MyGame/Example/NestedUnion/Any.py
Normal file
20
tests/MyGame/Example/NestedUnion/Any.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
# namespace: NestedUnion
|
||||||
|
|
||||||
|
class Any(object):
|
||||||
|
NONE = 0
|
||||||
|
Vec3 = 1
|
||||||
|
TestSimpleTableWithEnum = 2
|
||||||
|
|
||||||
|
def AnyCreator(unionType, table):
|
||||||
|
from flatbuffers.table import Table
|
||||||
|
if not isinstance(table, Table):
|
||||||
|
return None
|
||||||
|
if unionType == Any().Vec3:
|
||||||
|
import MyGame.Example.NestedUnion.Vec3
|
||||||
|
return MyGame.Example.NestedUnion.Vec3.Vec3T.InitFromBuf(table.Bytes, table.Pos)
|
||||||
|
if unionType == Any().TestSimpleTableWithEnum:
|
||||||
|
import MyGame.Example.NestedUnion.TestSimpleTableWithEnum
|
||||||
|
return MyGame.Example.NestedUnion.TestSimpleTableWithEnum.TestSimpleTableWithEnumT.InitFromBuf(table.Bytes, table.Pos)
|
||||||
|
return None
|
||||||
12
tests/MyGame/Example/NestedUnion/Color.py
Normal file
12
tests/MyGame/Example/NestedUnion/Color.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
# namespace: NestedUnion
|
||||||
|
|
||||||
|
# Composite components of Monster color.
|
||||||
|
class Color(object):
|
||||||
|
Red = 1
|
||||||
|
# \brief color Green
|
||||||
|
# Green is bit_flag with value (1u << 1)
|
||||||
|
Green = 2
|
||||||
|
# \brief color Blue (1u << 3)
|
||||||
|
Blue = 8
|
||||||
133
tests/MyGame/Example/NestedUnion/NestedUnionTest.py
Normal file
133
tests/MyGame/Example/NestedUnion/NestedUnionTest.py
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
# automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
# namespace: NestedUnion
|
||||||
|
|
||||||
|
import flatbuffers
|
||||||
|
from flatbuffers.compat import import_numpy
|
||||||
|
np = import_numpy()
|
||||||
|
|
||||||
|
class NestedUnionTest(object):
|
||||||
|
__slots__ = ['_tab']
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def GetRootAs(cls, buf, offset=0):
|
||||||
|
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
|
||||||
|
x = NestedUnionTest()
|
||||||
|
x.Init(buf, n + offset)
|
||||||
|
return x
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def GetRootAsNestedUnionTest(cls, buf, offset=0):
|
||||||
|
"""This method is deprecated. Please switch to GetRootAs."""
|
||||||
|
return cls.GetRootAs(buf, offset)
|
||||||
|
# NestedUnionTest
|
||||||
|
def Init(self, buf, pos):
|
||||||
|
self._tab = flatbuffers.table.Table(buf, pos)
|
||||||
|
|
||||||
|
# NestedUnionTest
|
||||||
|
def Name(self):
|
||||||
|
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
|
||||||
|
if o != 0:
|
||||||
|
return self._tab.String(o + self._tab.Pos)
|
||||||
|
return None
|
||||||
|
|
||||||
|
# NestedUnionTest
|
||||||
|
def DataType(self):
|
||||||
|
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
|
||||||
|
if o != 0:
|
||||||
|
return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
# NestedUnionTest
|
||||||
|
def Data(self):
|
||||||
|
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
|
||||||
|
if o != 0:
|
||||||
|
from flatbuffers.table import Table
|
||||||
|
obj = Table(bytearray(), 0)
|
||||||
|
self._tab.Union(obj, o)
|
||||||
|
return obj
|
||||||
|
return None
|
||||||
|
|
||||||
|
# NestedUnionTest
|
||||||
|
def Id(self):
|
||||||
|
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
|
||||||
|
if o != 0:
|
||||||
|
return self._tab.Get(flatbuffers.number_types.Int16Flags, o + self._tab.Pos)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def NestedUnionTestStart(builder): builder.StartObject(4)
|
||||||
|
def Start(builder):
|
||||||
|
return NestedUnionTestStart(builder)
|
||||||
|
def NestedUnionTestAddName(builder, name): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0)
|
||||||
|
def AddName(builder, name):
|
||||||
|
return NestedUnionTestAddName(builder, name)
|
||||||
|
def NestedUnionTestAddDataType(builder, dataType): builder.PrependUint8Slot(1, dataType, 0)
|
||||||
|
def AddDataType(builder, dataType):
|
||||||
|
return NestedUnionTestAddDataType(builder, dataType)
|
||||||
|
def NestedUnionTestAddData(builder, data): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(data), 0)
|
||||||
|
def AddData(builder, data):
|
||||||
|
return NestedUnionTestAddData(builder, data)
|
||||||
|
def NestedUnionTestAddId(builder, id): builder.PrependInt16Slot(3, id, 0)
|
||||||
|
def AddId(builder, id):
|
||||||
|
return NestedUnionTestAddId(builder, id)
|
||||||
|
def NestedUnionTestEnd(builder): return builder.EndObject()
|
||||||
|
def End(builder):
|
||||||
|
return NestedUnionTestEnd(builder)
|
||||||
|
import MyGame.Example.NestedUnion.Any
|
||||||
|
import MyGame.Example.NestedUnion.TestSimpleTableWithEnum
|
||||||
|
import MyGame.Example.NestedUnion.Vec3
|
||||||
|
try:
|
||||||
|
from typing import Union
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
class NestedUnionTestT(object):
|
||||||
|
|
||||||
|
# NestedUnionTestT
|
||||||
|
def __init__(self):
|
||||||
|
self.name = None # type: str
|
||||||
|
self.dataType = 0 # type: int
|
||||||
|
self.data = None # type: Union[None, MyGame.Example.NestedUnion.Vec3.Vec3T, MyGame.Example.NestedUnion.TestSimpleTableWithEnum.TestSimpleTableWithEnumT]
|
||||||
|
self.id = 0 # type: int
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def InitFromBuf(cls, buf, pos):
|
||||||
|
nestedUnionTest = NestedUnionTest()
|
||||||
|
nestedUnionTest.Init(buf, pos)
|
||||||
|
return cls.InitFromObj(nestedUnionTest)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def InitFromPackedBuf(cls, buf, pos=0):
|
||||||
|
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)
|
||||||
|
return cls.InitFromBuf(buf, pos+n)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def InitFromObj(cls, nestedUnionTest):
|
||||||
|
x = NestedUnionTestT()
|
||||||
|
x._UnPack(nestedUnionTest)
|
||||||
|
return x
|
||||||
|
|
||||||
|
# NestedUnionTestT
|
||||||
|
def _UnPack(self, nestedUnionTest):
|
||||||
|
if nestedUnionTest is None:
|
||||||
|
return
|
||||||
|
self.name = nestedUnionTest.Name()
|
||||||
|
self.dataType = nestedUnionTest.DataType()
|
||||||
|
self.data = MyGame.Example.NestedUnion.Any.AnyCreator(self.dataType, nestedUnionTest.Data())
|
||||||
|
self.id = nestedUnionTest.Id()
|
||||||
|
|
||||||
|
# NestedUnionTestT
|
||||||
|
def Pack(self, builder):
|
||||||
|
if self.name is not None:
|
||||||
|
name = builder.CreateString(self.name)
|
||||||
|
if self.data is not None:
|
||||||
|
data = self.data.Pack(builder)
|
||||||
|
NestedUnionTestStart(builder)
|
||||||
|
if self.name is not None:
|
||||||
|
NestedUnionTestAddName(builder, name)
|
||||||
|
NestedUnionTestAddDataType(builder, self.dataType)
|
||||||
|
if self.data is not None:
|
||||||
|
NestedUnionTestAddData(builder, data)
|
||||||
|
NestedUnionTestAddId(builder, self.id)
|
||||||
|
nestedUnionTest = NestedUnionTestEnd(builder)
|
||||||
|
return nestedUnionTest
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user