mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
Compare commits
58 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2cd1ea3b6 | ||
|
|
32e63af684 | ||
|
|
1f4a9038ce | ||
|
|
a9df44828d | ||
|
|
5f453ef738 | ||
|
|
49061f8c7c | ||
|
|
807adb73b2 | ||
|
|
2f59a0319b | ||
|
|
6a8898573c | ||
|
|
d7a70db6ac | ||
|
|
b127c57ff0 | ||
|
|
2436bd8175 | ||
|
|
69a53e495d | ||
|
|
c7a8102b12 | ||
|
|
2146bacd2e | ||
|
|
8db59321d9 | ||
|
|
42879f6ea6 | ||
|
|
7833affd7e | ||
|
|
c065e972db | ||
|
|
06b12d55ea | ||
|
|
baddf90599 | ||
|
|
8b35a6bc32 | ||
|
|
6cb4d671a8 | ||
|
|
fb9afbafc7 | ||
|
|
dafd2f1f29 | ||
|
|
6ede1ccc9e | ||
|
|
8755c35a18 | ||
|
|
75f05d6389 | ||
|
|
3b27f5396e | ||
|
|
58c8eb5847 | ||
|
|
0e034ecdba | ||
|
|
0f8b71180f | ||
|
|
a5a2da0161 | ||
|
|
28783927af | ||
|
|
a1378fbd16 | ||
|
|
dcacfc5b11 | ||
|
|
f9dabf511a | ||
|
|
5ba66f71c5 | ||
|
|
5adfac9fc3 | ||
|
|
c6fce30e9b | ||
|
|
ef30729a71 | ||
|
|
30ae5f189c | ||
|
|
299725fe2e | ||
|
|
a41fefa1a8 | ||
|
|
d89f611f6f | ||
|
|
150644d7f4 | ||
|
|
c696275eaf | ||
|
|
7106d86685 | ||
|
|
da6472013f | ||
|
|
e646392647 | ||
|
|
e040f4e975 | ||
|
|
f4a9c5325b | ||
|
|
8f2e1dbd88 | ||
|
|
595bf0007a | ||
|
|
0cfb7eb80b | ||
|
|
67eb95de92 | ||
|
|
b1f617fcb2 | ||
|
|
960cd4d635 |
@@ -5,7 +5,7 @@ platforms:
|
||||
ubuntu1804:
|
||||
environment:
|
||||
CC: clang
|
||||
SWIFT_VERSION: "5.5.3"
|
||||
SWIFT_VERSION: "5.8"
|
||||
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
|
||||
PATH: "$PATH:$SWIFT_HOME/usr/bin"
|
||||
shell_commands:
|
||||
@@ -19,7 +19,7 @@ platforms:
|
||||
ubuntu2004:
|
||||
environment:
|
||||
CC: clang
|
||||
SWIFT_VERSION: "5.5.3"
|
||||
SWIFT_VERSION: "5.8"
|
||||
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
|
||||
PATH: "$PATH:$SWIFT_HOME/usr/bin"
|
||||
shell_commands:
|
||||
@@ -31,7 +31,9 @@ platforms:
|
||||
test_targets:
|
||||
- "//..."
|
||||
macos:
|
||||
xcode_version: "14.3"
|
||||
build_targets:
|
||||
- "//..."
|
||||
- "//:flatbuffers"
|
||||
- "//:flatc"
|
||||
test_targets:
|
||||
- "//..."
|
||||
- "//tests:flatbuffers_test"
|
||||
|
||||
@@ -1 +1 @@
|
||||
node_modules
|
||||
ts/node_modules
|
||||
|
||||
12
.bazelrc
12
.bazelrc
@@ -1,4 +1,12 @@
|
||||
# We cannot use "common" here because the "version" command doesn't support
|
||||
# --deleted_packages. We need to specify it for both build and query instead.
|
||||
build --deleted_packages=tests/ts/bazel_repository_test_dir
|
||||
query --deleted_packages=tests/ts/bazel_repository_test_dir
|
||||
build --deleted_packages=tests/bazel_repository_test_dir,tests/ts/bazel_repository_test_dir
|
||||
query --deleted_packages=tests/bazel_repository_test_dir,tests/ts/bazel_repository_test_dir
|
||||
# Point tools such as coursier (used in rules_jvm_external) to Bazel's internal JDK
|
||||
# suggested in https://github.com/bazelbuild/rules_jvm_external/issues/445
|
||||
common --repo_env=JAVA_HOME=../bazel_tools/jdk
|
||||
common --action_env=JAVA_HOME=../bazel_tools/jdk
|
||||
# Workaround "Error: need --enable_runfiles on Windows for to support rules_js"
|
||||
common:windows --enable_runfiles
|
||||
# Swift is not required on Windows
|
||||
common:windows --deleted_packages=swift
|
||||
107
.github/workflows/build.yml
vendored
107
.github/workflows/build.yml
vendored
@@ -12,6 +12,9 @@ on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
schedule:
|
||||
# Run daily at 4:45 A.M. to catch dependencies that break us.
|
||||
- cron: '45 4 * * *'
|
||||
|
||||
jobs:
|
||||
build-linux:
|
||||
@@ -21,10 +24,10 @@ jobs:
|
||||
digests-gcc: ${{ steps.hash-gcc.outputs.hashes }}
|
||||
digests-clang: ${{ steps.hash-clang.outputs.hashes }}
|
||||
name: Build Linux
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
matrix:
|
||||
cxx: [g++-13, clang++-15]
|
||||
cxx: [g++-13, clang++-18]
|
||||
fail-fast: false
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
@@ -39,7 +42,7 @@ jobs:
|
||||
chmod +x flatc
|
||||
./flatc --version
|
||||
- name: upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: Linux flatc binary ${{ matrix.cxx }}
|
||||
path: flatc
|
||||
@@ -53,7 +56,7 @@ jobs:
|
||||
with:
|
||||
files: Linux.flatc.binary.${{ matrix.cxx }}.zip
|
||||
- name: Generate SLSA subjects - clang
|
||||
if: matrix.cxx == 'clang++-15' && startsWith(github.ref, 'refs/tags/')
|
||||
if: matrix.cxx == 'clang++-18' && startsWith(github.ref, 'refs/tags/')
|
||||
id: hash-clang
|
||||
run: echo "hashes=$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)" >> $GITHUB_OUTPUT
|
||||
- name: Generate SLSA subjects - gcc
|
||||
@@ -63,11 +66,11 @@ jobs:
|
||||
|
||||
build-linux-no-file-tests:
|
||||
name: Build Linux with -DFLATBUFFERS_NO_FILE_TESTS
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
run: CXX=clang++-15 cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_CXX_FLAGS="-DFLATBUFFERS_NO_FILE_TESTS" .
|
||||
run: CXX=clang++-18 cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_CXX_FLAGS="-DFLATBUFFERS_NO_FILE_TESTS" .
|
||||
- name: build
|
||||
run: make -j
|
||||
- name: test
|
||||
@@ -75,7 +78,7 @@ jobs:
|
||||
|
||||
build-linux-out-of-source:
|
||||
name: Build Linux with out-of-source build location
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: make build directory
|
||||
@@ -83,7 +86,7 @@ jobs:
|
||||
- name: cmake
|
||||
working-directory: build
|
||||
run: >
|
||||
CXX=clang++-15 cmake .. -G "Unix Makefiles" -DFLATBUFFERS_STRICT_MODE=ON
|
||||
CXX=clang++-18 cmake .. -G "Unix Makefiles" -DFLATBUFFERS_STRICT_MODE=ON
|
||||
-DFLATBUFFERS_BUILD_CPP17=ON -DFLATBUFFERS_CPP_STD=17
|
||||
- name: build
|
||||
working-directory: build
|
||||
@@ -97,15 +100,15 @@ jobs:
|
||||
|
||||
build-linux-cpp-std:
|
||||
name: Build Linux C++
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
std: [11, 14, 17, 20, 23]
|
||||
cxx: [g++-13, clang++-15]
|
||||
cxx: [g++-13, clang++-18]
|
||||
exclude:
|
||||
# Clang++15 10.3.0 stdlibc++ doesn't fully support std 23
|
||||
- cxx: clang++-15
|
||||
- cxx: clang++-18
|
||||
std: 23
|
||||
|
||||
steps:
|
||||
@@ -167,7 +170,7 @@ jobs:
|
||||
- name: test
|
||||
run: Release\flattests.exe
|
||||
- name: upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: Windows flatc binary
|
||||
path: Release\flatc.exe
|
||||
@@ -220,11 +223,11 @@ jobs:
|
||||
outputs:
|
||||
digests: ${{ steps.hash.outputs.hashes }}
|
||||
name: Build Mac (for Intel)
|
||||
runs-on: macos-latest
|
||||
runs-on: macos-latest-large
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
run: cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||
run: cmake -G "Xcode" -DCMAKE_OSX_ARCHITECTURES="x86_64" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||
- name: build
|
||||
run: xcodebuild -toolchain clang -configuration Release -target flattests
|
||||
- name: check that the binary is x86_64
|
||||
@@ -239,9 +242,9 @@ jobs:
|
||||
chmod +x Release/flatc
|
||||
Release/flatc --version
|
||||
- name: upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: Mac flatc binary
|
||||
name: Mac flatc binary Intel
|
||||
path: Release/flatc
|
||||
# Below if only for release.
|
||||
- name: Zip file
|
||||
@@ -282,9 +285,9 @@ jobs:
|
||||
chmod +x Release/flatc
|
||||
Release/flatc --version
|
||||
- name: upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: Mac flatc binary
|
||||
name: Mac flatc binary Universal
|
||||
path: Release/flatc
|
||||
# Below if only for release.
|
||||
- name: Zip file
|
||||
@@ -302,7 +305,7 @@ jobs:
|
||||
|
||||
build-android:
|
||||
name: Build Android (on Linux)
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: set up Java
|
||||
@@ -321,10 +324,10 @@ jobs:
|
||||
|
||||
build-generator:
|
||||
name: Check Generated Code
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
matrix:
|
||||
cxx: [g++-13, clang++-15]
|
||||
cxx: [g++-13, clang++-18]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
@@ -352,7 +355,7 @@ jobs:
|
||||
|
||||
build-benchmarks:
|
||||
name: Build Benchmarks (on Linux)
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
matrix:
|
||||
cxx: [g++-13]
|
||||
@@ -363,14 +366,14 @@ jobs:
|
||||
- name: Run benchmarks
|
||||
run: ./flatbenchmark --benchmark_repetitions=5 --benchmark_display_aggregates_only=true --benchmark_out_format=console --benchmark_out=benchmarks/results_${{matrix.cxx}}
|
||||
- name: Upload benchmarks results
|
||||
uses: actions/upload-artifact@v1
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: Linux flatbenchmark results ${{matrix.cxx}}
|
||||
path: benchmarks/results_${{matrix.cxx}}
|
||||
|
||||
build-java:
|
||||
name: Build Java
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: test
|
||||
@@ -379,10 +382,17 @@ jobs:
|
||||
|
||||
build-kotlin-macos:
|
||||
name: Build Kotlin MacOS
|
||||
runs-on: macos-latest
|
||||
runs-on: macos-13
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
# Force Xcode 14.3 since Xcode 15 doesnt support older versions of
|
||||
# kotlin. For Xcode 15, kotlin should be bumpped to 1.9.10
|
||||
# https://stackoverflow.com/a/77150623
|
||||
# For now, run with macos-13 which has this 14.3 installed:
|
||||
# https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md#xcode
|
||||
- name: Set up Xcode version
|
||||
run: sudo xcode-select -s /Applications/Xcode_14.3.app/Contents/Developer
|
||||
- uses: gradle/wrapper-validation-action@v1.0.5
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
@@ -399,7 +409,7 @@ jobs:
|
||||
|
||||
build-kotlin-linux:
|
||||
name: Build Kotlin Linux
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
@@ -422,7 +432,7 @@ jobs:
|
||||
|
||||
build-rust-linux:
|
||||
name: Build Rust Linux
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: test
|
||||
@@ -440,7 +450,7 @@ jobs:
|
||||
|
||||
build-python:
|
||||
name: Build Python
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: flatc
|
||||
@@ -452,7 +462,7 @@ jobs:
|
||||
|
||||
build-go:
|
||||
name: Build Go
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: flatc
|
||||
@@ -464,7 +474,7 @@ jobs:
|
||||
|
||||
build-php:
|
||||
name: Build PHP
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: flatc
|
||||
@@ -478,9 +488,18 @@ jobs:
|
||||
|
||||
build-swift:
|
||||
name: Build Swift
|
||||
runs-on: ubuntu-22.04-64core
|
||||
strategy:
|
||||
matrix:
|
||||
swift: ["5.8", "5.9", "5.10"]
|
||||
# Only 22.04 has swift at the moment https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md?plain=1#L30
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: swift-actions/setup-swift@v2
|
||||
with:
|
||||
swift-version: ${{ matrix.swift }}
|
||||
- name: Get swift version
|
||||
run: swift --version
|
||||
- name: test
|
||||
working-directory: tests/swift/tests
|
||||
run: |
|
||||
@@ -489,20 +508,22 @@ jobs:
|
||||
|
||||
build-swift-wasm:
|
||||
name: Build Swift Wasm
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
container:
|
||||
image: ghcr.io/swiftwasm/carton:0.15.3
|
||||
image: ghcr.io/swiftwasm/carton:0.20.1
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup Wasmer
|
||||
uses: wasmerio/setup-wasmer@v2
|
||||
- name: Test
|
||||
working-directory: tests/swift/Wasm.tests
|
||||
run: carton test
|
||||
- uses: actions/checkout@v3
|
||||
- uses: bytecodealliance/actions/wasmtime/setup@v1
|
||||
- uses: swiftwasm/setup-swiftwasm@v1
|
||||
with:
|
||||
swift-version: "wasm-6.0.2-RELEASE"
|
||||
- name: Test
|
||||
working-directory: tests/swift/Wasm.tests
|
||||
run: swift run carton test
|
||||
|
||||
build-ts:
|
||||
name: Build TS
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: flatc
|
||||
@@ -520,7 +541,7 @@ jobs:
|
||||
|
||||
build-dart:
|
||||
name: Build Dart
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: dart-lang/setup-dart@v1
|
||||
@@ -535,7 +556,7 @@ jobs:
|
||||
|
||||
build-nim:
|
||||
name: Build Nim
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: flatc
|
||||
@@ -554,7 +575,7 @@ jobs:
|
||||
needs: [build-linux, build-windows, build-mac-intel, build-mac-universal]
|
||||
outputs:
|
||||
digests: ${{ steps.hash.outputs.digests }}
|
||||
runs-on: ubuntu-22.04-64core
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Merge results
|
||||
id: hash
|
||||
|
||||
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
@@ -1,7 +1,7 @@
|
||||
name: OSS-Fuzz
|
||||
permissions: read-all
|
||||
|
||||
on:
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
@@ -27,7 +27,7 @@ jobs:
|
||||
language: c++
|
||||
fuzz-seconds: 60
|
||||
- name: Upload Crash
|
||||
uses: actions/upload-artifact@v1
|
||||
uses: actions/upload-artifact@v4
|
||||
if: failure() && steps.build.outcome == 'success'
|
||||
with:
|
||||
name: artifacts
|
||||
|
||||
49
.github/workflows/release.yml
vendored
49
.github/workflows/release.yml
vendored
@@ -5,7 +5,7 @@ on:
|
||||
# For manual tests.
|
||||
workflow_dispatch:
|
||||
release:
|
||||
types: [created]
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
publish-npm:
|
||||
@@ -100,6 +100,53 @@ jobs:
|
||||
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
|
||||
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
|
||||
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||
|
||||
publish-maven-kotlin:
|
||||
name: Publish Maven - Kotlin
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ./kotlin
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Maven Central Repository
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
cache: 'maven'
|
||||
server-id: ossrh
|
||||
server-username: OSSRH_USERNAME
|
||||
server-password: OSSRH_PASSWORD
|
||||
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
|
||||
gpg-passphrase: MAVEN_GPG_PASSPHRASE # this needs to be an env var
|
||||
|
||||
- name: Publish Kotlin Library on Maven
|
||||
run: ./gradlew publishAllPublicationsToSonatypeRepository
|
||||
env:
|
||||
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
|
||||
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
|
||||
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||
|
||||
|
||||
publish-crates:
|
||||
name: Publish crates.io
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
override: true
|
||||
|
||||
- name: Publish Flatbuffers
|
||||
uses: katyo/publish-crates@v2
|
||||
with:
|
||||
path: ./rust/flatbuffers
|
||||
registry-token: ${{ secrets.CARGO_TOKEN }}
|
||||
|
||||
- name: Publish Flexbuffers
|
||||
uses: katyo/publish-crates@v2
|
||||
with:
|
||||
path: ./rust/flexbuffers
|
||||
registry-token: ${{ secrets.CARGO_TOKEN }}
|
||||
|
||||
2
.github/workflows/scorecards.yml
vendored
2
.github/workflows/scorecards.yml
vendored
@@ -42,7 +42,7 @@ jobs:
|
||||
|
||||
# Upload the results as artifacts (optional).
|
||||
- name: "Upload artifact"
|
||||
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 # v3.0.0
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: SARIF file
|
||||
path: results.sarif
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -153,3 +153,5 @@ cmake-build-debug/
|
||||
_deps/
|
||||
**/.gradle/**
|
||||
kotlin/**/generated
|
||||
MODULE.bazel
|
||||
MODULE.bazel.lock
|
||||
|
||||
14
BUILD.bazel
14
BUILD.bazel
@@ -1,5 +1,3 @@
|
||||
load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
|
||||
load("@npm//:defs.bzl", "npm_link_all_packages")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
||||
|
||||
licenses(["notice"])
|
||||
@@ -8,13 +6,6 @@ package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
npm_link_all_packages(name = "node_modules")
|
||||
|
||||
npm_link_package(
|
||||
name = "node_modules/flatbuffers",
|
||||
src = "//ts:flatbuffers",
|
||||
)
|
||||
|
||||
exports_files([
|
||||
"LICENSE",
|
||||
"tsconfig.json",
|
||||
@@ -37,11 +28,16 @@ config_setting(
|
||||
filegroup(
|
||||
name = "distribution",
|
||||
srcs = [
|
||||
".bazelignore",
|
||||
".npmrc",
|
||||
"BUILD.bazel",
|
||||
"WORKSPACE",
|
||||
"build_defs.bzl",
|
||||
"package.json",
|
||||
"pnpm-lock.yaml",
|
||||
"typescript.bzl",
|
||||
"//grpc/src/compiler:distribution",
|
||||
"//include/codegen:distribution",
|
||||
"//reflection:distribution",
|
||||
"//src:distribution",
|
||||
"//ts:distribution",
|
||||
|
||||
@@ -4,6 +4,11 @@ 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
|
||||
necessarily listed.
|
||||
|
||||
## [24.3.25] (March 25 2024)(https://github.com/google/flatbuffers/releases/tag/v24.3.25)
|
||||
|
||||
* Fixed license metadata parsing (#8253)
|
||||
* [C++] Allow string_view in `LookUpByKey` in addition to null-terminated c-style strings (#8203)
|
||||
|
||||
## [24.3.7] (March 7 2024)(https://github.com/google/flatbuffers/releases/tag/v24.3.7)
|
||||
|
||||
* Just to fix some of the CI build issues from the 24.3.6 release.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
set(VERSION_MAJOR 24)
|
||||
set(VERSION_MINOR 3)
|
||||
set(VERSION_PATCH 7)
|
||||
set(VERSION_MINOR 12)
|
||||
set(VERSION_PATCH 23)
|
||||
set(VERSION_COMMIT 0)
|
||||
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||
|
||||
@@ -183,6 +183,10 @@ set(FlatBuffers_Compiler_SRCS
|
||||
src/bfbs_gen_lua.h
|
||||
src/bfbs_gen_nim.h
|
||||
src/bfbs_namer.h
|
||||
include/codegen/idl_namer.h
|
||||
include/codegen/namer.h
|
||||
include/codegen/python.h
|
||||
include/codegen/python.cc
|
||||
include/flatbuffers/code_generators.h
|
||||
src/binary_annotator.h
|
||||
src/binary_annotator.cpp
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'FlatBuffers'
|
||||
s.version = '24.3.7'
|
||||
s.version = '24.12.23'
|
||||
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
||||
|
||||
s.description = "FlatBuffers is a cross platform serialization library architected for
|
||||
@@ -10,12 +10,15 @@ Pod::Spec.new do |s|
|
||||
|
||||
s.homepage = 'https://github.com/google/flatbuffers'
|
||||
s.license = { :type => 'Apache2.0', :file => 'LICENSE' }
|
||||
s.author = { 'mustii' => 'mustii@mmk.one' }
|
||||
s.source = { :git => 'https://github.com/google/flatbuffers.git', :tag => s.version.to_s, :submodules => true }
|
||||
s.author = { 'mustii' => 'me@mustiikhalil.se' }
|
||||
s.source = { :git => 'https://github.com/google/flatbuffers.git', :tag => "v" + s.version.to_s, :submodules => true }
|
||||
|
||||
s.ios.deployment_target = '11.0'
|
||||
s.osx.deployment_target = '10.14'
|
||||
|
||||
s.swift_version = '5.0'
|
||||
s.source_files = 'swift/Sources/Flatbuffers/*.swift'
|
||||
s.pod_target_xcconfig = {
|
||||
'BUILD_LIBRARY_FOR_DISTRIBUTION' => 'YES'
|
||||
}
|
||||
end
|
||||
|
||||
6
MODULE.bazel
Normal file
6
MODULE.bazel
Normal file
@@ -0,0 +1,6 @@
|
||||
###############################################################################
|
||||
# Bazel now uses Bzlmod by default to manage external dependencies.
|
||||
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
|
||||
#
|
||||
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
|
||||
###############################################################################
|
||||
1632
MODULE.bazel.lock
generated
Normal file
1632
MODULE.bazel.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.6
|
||||
// swift-tools-version:5.8
|
||||
/*
|
||||
* Copyright 2020 Google Inc. All rights reserved.
|
||||
*
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
// swift-tools-version:5.5
|
||||
/*
|
||||
* Copyright 2020 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "FlatBuffers",
|
||||
platforms: [
|
||||
.iOS(.v11),
|
||||
.macOS(.v10_14),
|
||||
],
|
||||
products: [
|
||||
.library(
|
||||
name: "FlatBuffers",
|
||||
targets: ["FlatBuffers"]),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "FlatBuffers",
|
||||
dependencies: [],
|
||||
path: "swift/Sources"),
|
||||
])
|
||||
|
||||
@@ -18,7 +18,7 @@ maximum memory efficiency. It allows you to directly access serialized data with
|
||||
|
||||
1. Build the compiler for flatbuffers (`flatc`)
|
||||
|
||||
Use `cmake` to create the build files for your platform and then perform the compliation (Linux example).
|
||||
Use `cmake` to create the build files for your platform and then perform the compilation (Linux example).
|
||||
|
||||
```
|
||||
cmake -G "Unix Makefiles"
|
||||
|
||||
53
WORKSPACE
53
WORKSPACE
@@ -11,6 +11,21 @@ http_archive(
|
||||
],
|
||||
)
|
||||
|
||||
# Import our own version of skylib before other rule sets (e.g. rules_swift)
|
||||
# has a chance to import an old version.
|
||||
http_archive(
|
||||
name = "bazel_skylib",
|
||||
sha256 = "66ffd9315665bfaafc96b52278f57c7e2dd09f5ede279ea6d39b2be471e7e3aa",
|
||||
urls = [
|
||||
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz",
|
||||
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
|
||||
|
||||
bazel_skylib_workspace()
|
||||
|
||||
http_archive(
|
||||
name = "build_bazel_rules_apple",
|
||||
sha256 = "34c41bfb59cdaea29ac2df5a2fa79e5add609c71bb303b2ebb10985f93fa20e7",
|
||||
@@ -68,6 +83,28 @@ http_archive(
|
||||
],
|
||||
)
|
||||
|
||||
#### Building boring ssl
|
||||
# Fetching boringssl within the flatbuffers repository, to patch the issue
|
||||
# of not being able to upgrade to Xcode 14.3 due to buildkite throwing errors
|
||||
# which was patched in the following below.
|
||||
# https://github.com/google/flatbuffers/commit/67eb95de9281087ccbba9aafd6e8ab1958d12045
|
||||
# The patch was copied from the following comment on the same issue within tensorflow
|
||||
# and fixed to adapt the already existing patch for boringssl.
|
||||
# https://github.com/tensorflow/tensorflow/issues/60191#issuecomment-1496073147
|
||||
http_archive(
|
||||
name = "boringssl",
|
||||
patch_args = ["-p1"],
|
||||
patches = ["//grpc:boringssl.patch"],
|
||||
# Use github mirror instead of https://boringssl.googlesource.com/boringssl
|
||||
# to obtain a boringssl archive with consistent sha256
|
||||
sha256 = "534fa658bd845fd974b50b10f444d392dfd0d93768c4a51b61263fd37d851c40",
|
||||
strip_prefix = "boringssl-b9232f9e27e5668bc0414879dcdedb2a59ea75f2",
|
||||
urls = [
|
||||
"https://storage.googleapis.com/grpc-bazel-mirror/github.com/google/boringssl/archive/b9232f9e27e5668bc0414879dcdedb2a59ea75f2.tar.gz",
|
||||
"https://github.com/google/boringssl/archive/b9232f9e27e5668bc0414879dcdedb2a59ea75f2.tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
##### GRPC
|
||||
_GRPC_VERSION = "1.49.0" # https://github.com/grpc/grpc/releases/tag/v1.48.0
|
||||
|
||||
@@ -101,7 +138,7 @@ load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
|
||||
|
||||
rules_js_dependencies()
|
||||
|
||||
load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock", "pnpm_repository")
|
||||
load("@aspect_rules_js//npm:npm_import.bzl", "pnpm_repository")
|
||||
|
||||
pnpm_repository(name = "pnpm")
|
||||
|
||||
@@ -129,17 +166,13 @@ nodejs_register_toolchains(
|
||||
node_version = DEFAULT_NODE_VERSION,
|
||||
)
|
||||
|
||||
npm_translate_lock(
|
||||
name = "npm",
|
||||
npmrc = "//:.npmrc",
|
||||
pnpm_lock = "//:pnpm-lock.yaml",
|
||||
# Set this to True when the lock file needs to be updated, commit the
|
||||
# changes, then set to False again.
|
||||
update_pnpm_lock = False,
|
||||
verify_node_modules_ignored = "//:.bazelignore",
|
||||
load("@com_github_google_flatbuffers//ts:repositories.bzl", "flatbuffers_npm")
|
||||
|
||||
flatbuffers_npm(
|
||||
name = "flatbuffers_npm",
|
||||
)
|
||||
|
||||
load("@npm//:repositories.bzl", "npm_repositories")
|
||||
load("@flatbuffers_npm//:repositories.bzl", "npm_repositories")
|
||||
|
||||
npm_repositories()
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 23 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 1 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 21,
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 24 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 12 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 23,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace com {
|
||||
|
||||
@@ -57,7 +57,7 @@ class Animal : Table() {
|
||||
return if(o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
|
||||
}
|
||||
companion object {
|
||||
fun validateVersion() = Constants.FLATBUFFERS_24_3_7()
|
||||
fun validateVersion() = Constants.FLATBUFFERS_24_12_23()
|
||||
fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal())
|
||||
fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 24 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 12 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 23,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace benchmarks_flatbuffers {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
* Copyright 2024 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -178,4 +178,24 @@ let benchmarks = {
|
||||
let root = Offset(offset: fb.endTable(at: start))
|
||||
fb.finish(offset: root)
|
||||
}
|
||||
|
||||
Benchmark("Vector of Offsets") { benchmark in
|
||||
let rawSize = ((16 * 5) * benchmark.scaledIterations.count) / 1024
|
||||
var fb = FlatBufferBuilder(initialSize: Int32(rawSize * 1600))
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
let offsets = [
|
||||
fb.create(string: "T"),
|
||||
fb.create(string: "2"),
|
||||
fb.create(string: "3"),
|
||||
]
|
||||
let off = fb.createVector(ofOffsets: [
|
||||
fb.createVector(ofOffsets: offsets),
|
||||
fb.createVector(ofOffsets: offsets),
|
||||
])
|
||||
let s = fb.startTable(with: 2)
|
||||
fb.add(offset: off, at: 2)
|
||||
blackHole(fb.endTable(at: s))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ let package = Package(
|
||||
.package(path: "../.."),
|
||||
.package(
|
||||
url: "https://github.com/ordo-one/package-benchmark",
|
||||
from: "1.12.0"),
|
||||
from: "1.27.0"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
|
||||
@@ -386,7 +386,7 @@ class Builder {
|
||||
/// Updates the [offset] pointer. This method is intended for use when writing structs to the buffer.
|
||||
void putFloat64(double value) {
|
||||
_prepare(_sizeofFloat64, 1);
|
||||
_setFloat32AtTail(_tail, value);
|
||||
_setFloat64AtTail(_tail, value);
|
||||
}
|
||||
|
||||
/// Writes a Float32 to the tail of the buffer after preparing space for it.
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
name: flat_buffers
|
||||
version: 24.3.7
|
||||
version: 24.12.23
|
||||
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
|
||||
documentation: https://google.github.io/flatbuffers/index.html
|
||||
|
||||
environment:
|
||||
sdk: '>=2.12.0 <4.0.0'
|
||||
sdk: '>=2.17.0 <4.0.0'
|
||||
|
||||
dev_dependencies:
|
||||
test: ^1.17.7
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||
|
||||
import 'dart:typed_data' show Uint8List;
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
@@ -1,43 +1,33 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||
|
||||
import 'dart:typed_data' show Uint8List;
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
|
||||
class OptionsEnum {
|
||||
enum OptionsEnum {
|
||||
A(1),
|
||||
B(2),
|
||||
C(3);
|
||||
|
||||
final int value;
|
||||
const OptionsEnum._(this.value);
|
||||
const OptionsEnum(this.value);
|
||||
|
||||
factory OptionsEnum.fromValue(int value) {
|
||||
final result = values[value];
|
||||
if (result == null) {
|
||||
throw StateError('Invalid value $value for bit flag enum OptionsEnum');
|
||||
switch (value) {
|
||||
case 1: return OptionsEnum.A;
|
||||
case 2: return OptionsEnum.B;
|
||||
case 3: return OptionsEnum.C;
|
||||
default: throw StateError('Invalid value $value for bit flag enum');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static OptionsEnum? _createOrNull(int? value) =>
|
||||
static OptionsEnum? _createOrNull(int? value) =>
|
||||
value == null ? null : OptionsEnum.fromValue(value);
|
||||
|
||||
static const int minValue = 1;
|
||||
static const int maxValue = 3;
|
||||
static bool containsValue(int value) => values.containsKey(value);
|
||||
|
||||
static const OptionsEnum A = OptionsEnum._(1);
|
||||
static const OptionsEnum B = OptionsEnum._(2);
|
||||
static const OptionsEnum C = OptionsEnum._(3);
|
||||
static const Map<int, OptionsEnum> values = {
|
||||
1: A,
|
||||
2: B,
|
||||
3: C};
|
||||
|
||||
static const fb.Reader<OptionsEnum> reader = _OptionsEnumReader();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'OptionsEnum{value: $value}';
|
||||
}
|
||||
}
|
||||
|
||||
class _OptionsEnumReader extends fb.Reader<OptionsEnum> {
|
||||
@@ -9,7 +9,7 @@ import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import './monster_test_my_game.example_generated.dart' as example;
|
||||
import './monster_test_my_game.example2_generated.dart' as example2;
|
||||
import './list_of_enums_generated.dart' as example3;
|
||||
import 'enums_generated.dart' as example3;
|
||||
import './bool_structs_generated.dart' as example4;
|
||||
|
||||
main() {
|
||||
@@ -63,11 +63,11 @@ class CheckOtherLangaugesData {
|
||||
expect(
|
||||
mon.toString(),
|
||||
'Monster{'
|
||||
'pos: Vec3{x: 1.0, y: 2.0, z: 3.0, test1: 3.0, test2: Color{value: 2}, test3: Test{a: 5, b: 6}}, '
|
||||
'pos: Vec3{x: 1.0, y: 2.0, z: 3.0, test1: 3.0, test2: Color.Green, test3: Test{a: 5, b: 6}}, '
|
||||
'mana: 150, hp: 80, name: MyMonster, inventory: [0, 1, 2, 3, 4], '
|
||||
'color: Color{value: 8}, testType: AnyTypeId{value: 1}, '
|
||||
'color: Color.Blue, testType: AnyTypeId.Monster, '
|
||||
'test: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
|
||||
'inventory: null, color: Color{value: 8}, testType: null, '
|
||||
'inventory: null, color: Color.Blue, testType: null, '
|
||||
'test: null, test4: null, testarrayofstring: null, '
|
||||
'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, '
|
||||
'testempty: null, testbool: false, testhashs32Fnv1: 0, '
|
||||
@@ -82,18 +82,18 @@ class CheckOtherLangaugesData {
|
||||
'coOwningReference: 0, vectorOfCoOwningReferences: null, '
|
||||
'nonOwningReference: 0, vectorOfNonOwningReferences: null, '
|
||||
'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race.None, '
|
||||
'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, '
|
||||
'nativeInline: null, '
|
||||
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, '
|
||||
'longEnumNonEnumDefault: LongEnum._default, '
|
||||
'longEnumNormalDefault: LongEnum.LongOne, nanDefault: NaN, '
|
||||
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
|
||||
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
|
||||
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, '
|
||||
'test4: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], '
|
||||
'testarrayofstring: [test1, test2], testarrayoftables: null, '
|
||||
'enemy: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
|
||||
'inventory: null, color: Color{value: 8}, testType: null, '
|
||||
'inventory: null, color: Color.Blue, testType: null, '
|
||||
'test: null, test4: null, testarrayofstring: null, '
|
||||
'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, '
|
||||
'testempty: null, testbool: false, testhashs32Fnv1: 0, '
|
||||
@@ -108,11 +108,11 @@ class CheckOtherLangaugesData {
|
||||
'coOwningReference: 0, vectorOfCoOwningReferences: null, '
|
||||
'nonOwningReference: 0, vectorOfNonOwningReferences: null, '
|
||||
'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race.None, '
|
||||
'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, '
|
||||
'nativeInline: null, '
|
||||
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, '
|
||||
'longEnumNonEnumDefault: LongEnum._default, '
|
||||
'longEnumNormalDefault: LongEnum.LongOne, nanDefault: NaN, '
|
||||
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
|
||||
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
|
||||
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, '
|
||||
@@ -137,12 +137,12 @@ class CheckOtherLangaugesData {
|
||||
'vectorOfNonOwningReferences: null, '
|
||||
'anyUniqueType: null, anyUnique: null, '
|
||||
'anyAmbiguousType: null, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race.None, '
|
||||
'testrequirednestedflatbuffer: null, scalarKeySortedTables: [Stat{id: '
|
||||
'miss, val: 0, count: 0}, Stat{id: hit, val: 10, count: 1}], '
|
||||
'nativeInline: Test{a: 1, b: 2}, '
|
||||
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, '
|
||||
'longEnumNonEnumDefault: LongEnum._default, '
|
||||
'longEnumNormalDefault: LongEnum.LongOne, nanDefault: NaN, '
|
||||
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
|
||||
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
|
||||
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}');
|
||||
@@ -215,6 +215,10 @@ class BuilderTest {
|
||||
..addTestarrayofstringOffset(testArrayOfString);
|
||||
final mon = monBuilder.finish();
|
||||
fbBuilder.finish(mon);
|
||||
|
||||
final mon3 = example.Monster(fbBuilder.buffer);
|
||||
expect(mon3.name, 'MyMonster');
|
||||
expect(mon3.pos!.test1, 3.0);
|
||||
}
|
||||
|
||||
void test_error_addInt32_withoutStartTable([Builder? builder]) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||
|
||||
import 'dart:typed_data' show Uint8List;
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||
|
||||
library my_game.other_name_space;
|
||||
|
||||
@@ -9,35 +9,25 @@ import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
import './include_test1_generated.dart';
|
||||
|
||||
class FromInclude {
|
||||
enum FromInclude {
|
||||
IncludeVal(0);
|
||||
|
||||
final int value;
|
||||
const FromInclude._(this.value);
|
||||
const FromInclude(this.value);
|
||||
|
||||
factory FromInclude.fromValue(int value) {
|
||||
final result = values[value];
|
||||
if (result == null) {
|
||||
throw StateError('Invalid value $value for bit flag enum FromInclude');
|
||||
switch (value) {
|
||||
case 0: return FromInclude.IncludeVal;
|
||||
default: throw StateError('Invalid value $value for bit flag enum');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static FromInclude? _createOrNull(int? value) =>
|
||||
static FromInclude? _createOrNull(int? value) =>
|
||||
value == null ? null : FromInclude.fromValue(value);
|
||||
|
||||
static const int minValue = 0;
|
||||
static const int maxValue = 0;
|
||||
static bool containsValue(int value) => values.containsKey(value);
|
||||
|
||||
static const FromInclude IncludeVal = FromInclude._(0);
|
||||
static const Map<int, FromInclude> values = {
|
||||
0: IncludeVal};
|
||||
|
||||
static const fb.Reader<FromInclude> reader = _FromIncludeReader();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'FromInclude{value: $value}';
|
||||
}
|
||||
}
|
||||
|
||||
class _FromIncludeReader extends fb.Reader<FromInclude> {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||
|
||||
library keyword_test;
|
||||
|
||||
@@ -7,39 +7,29 @@ import 'dart:typed_data' show Uint8List;
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
|
||||
class Abc {
|
||||
enum Abc {
|
||||
$void(0),
|
||||
where(1),
|
||||
stackalloc(2);
|
||||
|
||||
final int value;
|
||||
const Abc._(this.value);
|
||||
const Abc(this.value);
|
||||
|
||||
factory Abc.fromValue(int value) {
|
||||
final result = values[value];
|
||||
if (result == null) {
|
||||
throw StateError('Invalid value $value for bit flag enum Abc');
|
||||
switch (value) {
|
||||
case 0: return Abc.$void;
|
||||
case 1: return Abc.where;
|
||||
case 2: return Abc.stackalloc;
|
||||
default: throw StateError('Invalid value $value for bit flag enum');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static Abc? _createOrNull(int? value) =>
|
||||
static Abc? _createOrNull(int? value) =>
|
||||
value == null ? null : Abc.fromValue(value);
|
||||
|
||||
static const int minValue = 0;
|
||||
static const int maxValue = 2;
|
||||
static bool containsValue(int value) => values.containsKey(value);
|
||||
|
||||
static const Abc $void = Abc._(0);
|
||||
static const Abc where = Abc._(1);
|
||||
static const Abc stackalloc = Abc._(2);
|
||||
static const Map<int, Abc> values = {
|
||||
0: $void,
|
||||
1: where,
|
||||
2: stackalloc};
|
||||
|
||||
static const fb.Reader<Abc> reader = _AbcReader();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Abc{value: $value}';
|
||||
}
|
||||
}
|
||||
|
||||
class _AbcReader extends fb.Reader<Abc> {
|
||||
@@ -53,35 +43,25 @@ class _AbcReader extends fb.Reader<Abc> {
|
||||
Abc.fromValue(const fb.Int32Reader().read(bc, offset));
|
||||
}
|
||||
|
||||
class Public {
|
||||
enum Public {
|
||||
NONE(0);
|
||||
|
||||
final int value;
|
||||
const Public._(this.value);
|
||||
const Public(this.value);
|
||||
|
||||
factory Public.fromValue(int value) {
|
||||
final result = values[value];
|
||||
if (result == null) {
|
||||
throw StateError('Invalid value $value for bit flag enum Public');
|
||||
switch (value) {
|
||||
case 0: return Public.NONE;
|
||||
default: throw StateError('Invalid value $value for bit flag enum');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static Public? _createOrNull(int? value) =>
|
||||
static Public? _createOrNull(int? value) =>
|
||||
value == null ? null : Public.fromValue(value);
|
||||
|
||||
static const int minValue = 0;
|
||||
static const int maxValue = 0;
|
||||
static bool containsValue(int value) => values.containsKey(value);
|
||||
|
||||
static const Public NONE = Public._(0);
|
||||
static const Map<int, Public> values = {
|
||||
0: NONE};
|
||||
|
||||
static const fb.Reader<Public> reader = _PublicReader();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Public{value: $value}';
|
||||
}
|
||||
}
|
||||
|
||||
class _PublicReader extends fb.Reader<Public> {
|
||||
@@ -95,39 +75,29 @@ class _PublicReader extends fb.Reader<Public> {
|
||||
Public.fromValue(const fb.Int32Reader().read(bc, offset));
|
||||
}
|
||||
|
||||
class KeywordsInUnionTypeId {
|
||||
enum KeywordsInUnionTypeId {
|
||||
NONE(0),
|
||||
$static(1),
|
||||
internal(2);
|
||||
|
||||
final int value;
|
||||
const KeywordsInUnionTypeId._(this.value);
|
||||
const KeywordsInUnionTypeId(this.value);
|
||||
|
||||
factory KeywordsInUnionTypeId.fromValue(int value) {
|
||||
final result = values[value];
|
||||
if (result == null) {
|
||||
throw StateError('Invalid value $value for bit flag enum KeywordsInUnionTypeId');
|
||||
switch (value) {
|
||||
case 0: return KeywordsInUnionTypeId.NONE;
|
||||
case 1: return KeywordsInUnionTypeId.$static;
|
||||
case 2: return KeywordsInUnionTypeId.internal;
|
||||
default: throw StateError('Invalid value $value for bit flag enum');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static KeywordsInUnionTypeId? _createOrNull(int? value) =>
|
||||
static KeywordsInUnionTypeId? _createOrNull(int? value) =>
|
||||
value == null ? null : KeywordsInUnionTypeId.fromValue(value);
|
||||
|
||||
static const int minValue = 0;
|
||||
static const int maxValue = 2;
|
||||
static bool containsValue(int value) => values.containsKey(value);
|
||||
|
||||
static const KeywordsInUnionTypeId NONE = KeywordsInUnionTypeId._(0);
|
||||
static const KeywordsInUnionTypeId $static = KeywordsInUnionTypeId._(1);
|
||||
static const KeywordsInUnionTypeId internal = KeywordsInUnionTypeId._(2);
|
||||
static const Map<int, KeywordsInUnionTypeId> values = {
|
||||
0: NONE,
|
||||
1: $static,
|
||||
2: internal};
|
||||
|
||||
static const fb.Reader<KeywordsInUnionTypeId> reader = _KeywordsInUnionTypeIdReader();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'KeywordsInUnionTypeId{value: $value}';
|
||||
}
|
||||
}
|
||||
|
||||
class _KeywordsInUnionTypeIdReader extends fb.Reader<KeywordsInUnionTypeId> {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||
|
||||
library my_game.example2;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||
|
||||
library my_game.example;
|
||||
|
||||
@@ -12,46 +12,29 @@ import './monster_test_my_game.example2_generated.dart' as my_game_example2;
|
||||
import './include_test1_generated.dart';
|
||||
|
||||
/// Composite components of Monster color.
|
||||
class Color {
|
||||
enum Color {
|
||||
Red(1),
|
||||
Green(2),
|
||||
Blue(8),
|
||||
_default(0);
|
||||
|
||||
final int value;
|
||||
const Color._(this.value);
|
||||
const Color(this.value);
|
||||
|
||||
factory Color.fromValue(int value) {
|
||||
final result = values[value];
|
||||
if (result == null) {
|
||||
if (value == 0) {
|
||||
return Color._(0);
|
||||
} else {
|
||||
throw StateError('Invalid value $value for bit flag enum Color');
|
||||
}
|
||||
switch (value) {
|
||||
case 1: return Color.Red;
|
||||
case 2: return Color.Green;
|
||||
case 8: return Color.Blue;
|
||||
case 0: return Color._default;
|
||||
default: throw StateError('Invalid value $value for bit flag enum');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static Color? _createOrNull(int? value) =>
|
||||
static Color? _createOrNull(int? value) =>
|
||||
value == null ? null : Color.fromValue(value);
|
||||
|
||||
static bool containsValue(int value) => values.containsKey(value);
|
||||
|
||||
static const Color Red = Color._(1);
|
||||
|
||||
/// \brief color Green
|
||||
/// Green is bit_flag with value (1u << 1)
|
||||
static const Color Green = Color._(2);
|
||||
|
||||
/// \brief color Blue (1u << 3)
|
||||
static const Color Blue = Color._(8);
|
||||
static const Map<int, Color> values = {
|
||||
1: Red,
|
||||
2: Green,
|
||||
8: Blue};
|
||||
|
||||
static const fb.Reader<Color> reader = _ColorReader();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Color{value: $value}';
|
||||
}
|
||||
}
|
||||
|
||||
class _ColorReader extends fb.Reader<Color> {
|
||||
@@ -65,41 +48,31 @@ class _ColorReader extends fb.Reader<Color> {
|
||||
Color.fromValue(const fb.Uint8Reader().read(bc, offset));
|
||||
}
|
||||
|
||||
class Race {
|
||||
enum Race {
|
||||
None(-1),
|
||||
Human(0),
|
||||
Dwarf(1),
|
||||
Elf(2);
|
||||
|
||||
final int value;
|
||||
const Race._(this.value);
|
||||
const Race(this.value);
|
||||
|
||||
factory Race.fromValue(int value) {
|
||||
final result = values[value];
|
||||
if (result == null) {
|
||||
throw StateError('Invalid value $value for bit flag enum Race');
|
||||
switch (value) {
|
||||
case -1: return Race.None;
|
||||
case 0: return Race.Human;
|
||||
case 1: return Race.Dwarf;
|
||||
case 2: return Race.Elf;
|
||||
default: throw StateError('Invalid value $value for bit flag enum');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static Race? _createOrNull(int? value) =>
|
||||
static Race? _createOrNull(int? value) =>
|
||||
value == null ? null : Race.fromValue(value);
|
||||
|
||||
static const int minValue = -1;
|
||||
static const int maxValue = 2;
|
||||
static bool containsValue(int value) => values.containsKey(value);
|
||||
|
||||
static const Race None = Race._(-1);
|
||||
static const Race Human = Race._(0);
|
||||
static const Race Dwarf = Race._(1);
|
||||
static const Race Elf = Race._(2);
|
||||
static const Map<int, Race> values = {
|
||||
-1: None,
|
||||
0: Human,
|
||||
1: Dwarf,
|
||||
2: Elf};
|
||||
|
||||
static const fb.Reader<Race> reader = _RaceReader();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Race{value: $value}';
|
||||
}
|
||||
}
|
||||
|
||||
class _RaceReader extends fb.Reader<Race> {
|
||||
@@ -113,41 +86,29 @@ class _RaceReader extends fb.Reader<Race> {
|
||||
Race.fromValue(const fb.Int8Reader().read(bc, offset));
|
||||
}
|
||||
|
||||
class LongEnum {
|
||||
enum LongEnum {
|
||||
LongOne(2),
|
||||
LongTwo(4),
|
||||
LongBig(1099511627776),
|
||||
_default(0);
|
||||
|
||||
final int value;
|
||||
const LongEnum._(this.value);
|
||||
const LongEnum(this.value);
|
||||
|
||||
factory LongEnum.fromValue(int value) {
|
||||
final result = values[value];
|
||||
if (result == null) {
|
||||
if (value == 0) {
|
||||
return LongEnum._(0);
|
||||
} else {
|
||||
throw StateError('Invalid value $value for bit flag enum LongEnum');
|
||||
}
|
||||
switch (value) {
|
||||
case 2: return LongEnum.LongOne;
|
||||
case 4: return LongEnum.LongTwo;
|
||||
case 1099511627776: return LongEnum.LongBig;
|
||||
case 0: return LongEnum._default;
|
||||
default: throw StateError('Invalid value $value for bit flag enum');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static LongEnum? _createOrNull(int? value) =>
|
||||
static LongEnum? _createOrNull(int? value) =>
|
||||
value == null ? null : LongEnum.fromValue(value);
|
||||
|
||||
static bool containsValue(int value) => values.containsKey(value);
|
||||
|
||||
static const LongEnum LongOne = LongEnum._(2);
|
||||
static const LongEnum LongTwo = LongEnum._(4);
|
||||
static const LongEnum LongBig = LongEnum._(1099511627776);
|
||||
static const Map<int, LongEnum> values = {
|
||||
2: LongOne,
|
||||
4: LongTwo,
|
||||
1099511627776: LongBig};
|
||||
|
||||
static const fb.Reader<LongEnum> reader = _LongEnumReader();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'LongEnum{value: $value}';
|
||||
}
|
||||
}
|
||||
|
||||
class _LongEnumReader extends fb.Reader<LongEnum> {
|
||||
@@ -161,41 +122,31 @@ class _LongEnumReader extends fb.Reader<LongEnum> {
|
||||
LongEnum.fromValue(const fb.Uint64Reader().read(bc, offset));
|
||||
}
|
||||
|
||||
class AnyTypeId {
|
||||
enum AnyTypeId {
|
||||
NONE(0),
|
||||
Monster(1),
|
||||
TestSimpleTableWithEnum(2),
|
||||
MyGame_Example2_Monster(3);
|
||||
|
||||
final int value;
|
||||
const AnyTypeId._(this.value);
|
||||
const AnyTypeId(this.value);
|
||||
|
||||
factory AnyTypeId.fromValue(int value) {
|
||||
final result = values[value];
|
||||
if (result == null) {
|
||||
throw StateError('Invalid value $value for bit flag enum AnyTypeId');
|
||||
switch (value) {
|
||||
case 0: return AnyTypeId.NONE;
|
||||
case 1: return AnyTypeId.Monster;
|
||||
case 2: return AnyTypeId.TestSimpleTableWithEnum;
|
||||
case 3: return AnyTypeId.MyGame_Example2_Monster;
|
||||
default: throw StateError('Invalid value $value for bit flag enum');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static AnyTypeId? _createOrNull(int? value) =>
|
||||
static AnyTypeId? _createOrNull(int? value) =>
|
||||
value == null ? null : AnyTypeId.fromValue(value);
|
||||
|
||||
static const int minValue = 0;
|
||||
static const int maxValue = 3;
|
||||
static bool containsValue(int value) => values.containsKey(value);
|
||||
|
||||
static const AnyTypeId NONE = AnyTypeId._(0);
|
||||
static const AnyTypeId Monster = AnyTypeId._(1);
|
||||
static const AnyTypeId TestSimpleTableWithEnum = AnyTypeId._(2);
|
||||
static const AnyTypeId MyGame_Example2_Monster = AnyTypeId._(3);
|
||||
static const Map<int, AnyTypeId> values = {
|
||||
0: NONE,
|
||||
1: Monster,
|
||||
2: TestSimpleTableWithEnum,
|
||||
3: MyGame_Example2_Monster};
|
||||
|
||||
static const fb.Reader<AnyTypeId> reader = _AnyTypeIdReader();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AnyTypeId{value: $value}';
|
||||
}
|
||||
}
|
||||
|
||||
class _AnyTypeIdReader extends fb.Reader<AnyTypeId> {
|
||||
@@ -209,41 +160,31 @@ class _AnyTypeIdReader extends fb.Reader<AnyTypeId> {
|
||||
AnyTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
|
||||
}
|
||||
|
||||
class AnyUniqueAliasesTypeId {
|
||||
enum AnyUniqueAliasesTypeId {
|
||||
NONE(0),
|
||||
M(1),
|
||||
TS(2),
|
||||
M2(3);
|
||||
|
||||
final int value;
|
||||
const AnyUniqueAliasesTypeId._(this.value);
|
||||
const AnyUniqueAliasesTypeId(this.value);
|
||||
|
||||
factory AnyUniqueAliasesTypeId.fromValue(int value) {
|
||||
final result = values[value];
|
||||
if (result == null) {
|
||||
throw StateError('Invalid value $value for bit flag enum AnyUniqueAliasesTypeId');
|
||||
switch (value) {
|
||||
case 0: return AnyUniqueAliasesTypeId.NONE;
|
||||
case 1: return AnyUniqueAliasesTypeId.M;
|
||||
case 2: return AnyUniqueAliasesTypeId.TS;
|
||||
case 3: return AnyUniqueAliasesTypeId.M2;
|
||||
default: throw StateError('Invalid value $value for bit flag enum');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static AnyUniqueAliasesTypeId? _createOrNull(int? value) =>
|
||||
static AnyUniqueAliasesTypeId? _createOrNull(int? value) =>
|
||||
value == null ? null : AnyUniqueAliasesTypeId.fromValue(value);
|
||||
|
||||
static const int minValue = 0;
|
||||
static const int maxValue = 3;
|
||||
static bool containsValue(int value) => values.containsKey(value);
|
||||
|
||||
static const AnyUniqueAliasesTypeId NONE = AnyUniqueAliasesTypeId._(0);
|
||||
static const AnyUniqueAliasesTypeId M = AnyUniqueAliasesTypeId._(1);
|
||||
static const AnyUniqueAliasesTypeId TS = AnyUniqueAliasesTypeId._(2);
|
||||
static const AnyUniqueAliasesTypeId M2 = AnyUniqueAliasesTypeId._(3);
|
||||
static const Map<int, AnyUniqueAliasesTypeId> values = {
|
||||
0: NONE,
|
||||
1: M,
|
||||
2: TS,
|
||||
3: M2};
|
||||
|
||||
static const fb.Reader<AnyUniqueAliasesTypeId> reader = _AnyUniqueAliasesTypeIdReader();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AnyUniqueAliasesTypeId{value: $value}';
|
||||
}
|
||||
}
|
||||
|
||||
class _AnyUniqueAliasesTypeIdReader extends fb.Reader<AnyUniqueAliasesTypeId> {
|
||||
@@ -257,41 +198,31 @@ class _AnyUniqueAliasesTypeIdReader extends fb.Reader<AnyUniqueAliasesTypeId> {
|
||||
AnyUniqueAliasesTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
|
||||
}
|
||||
|
||||
class AnyAmbiguousAliasesTypeId {
|
||||
enum AnyAmbiguousAliasesTypeId {
|
||||
NONE(0),
|
||||
M1(1),
|
||||
M2(2),
|
||||
M3(3);
|
||||
|
||||
final int value;
|
||||
const AnyAmbiguousAliasesTypeId._(this.value);
|
||||
const AnyAmbiguousAliasesTypeId(this.value);
|
||||
|
||||
factory AnyAmbiguousAliasesTypeId.fromValue(int value) {
|
||||
final result = values[value];
|
||||
if (result == null) {
|
||||
throw StateError('Invalid value $value for bit flag enum AnyAmbiguousAliasesTypeId');
|
||||
switch (value) {
|
||||
case 0: return AnyAmbiguousAliasesTypeId.NONE;
|
||||
case 1: return AnyAmbiguousAliasesTypeId.M1;
|
||||
case 2: return AnyAmbiguousAliasesTypeId.M2;
|
||||
case 3: return AnyAmbiguousAliasesTypeId.M3;
|
||||
default: throw StateError('Invalid value $value for bit flag enum');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static AnyAmbiguousAliasesTypeId? _createOrNull(int? value) =>
|
||||
static AnyAmbiguousAliasesTypeId? _createOrNull(int? value) =>
|
||||
value == null ? null : AnyAmbiguousAliasesTypeId.fromValue(value);
|
||||
|
||||
static const int minValue = 0;
|
||||
static const int maxValue = 3;
|
||||
static bool containsValue(int value) => values.containsKey(value);
|
||||
|
||||
static const AnyAmbiguousAliasesTypeId NONE = AnyAmbiguousAliasesTypeId._(0);
|
||||
static const AnyAmbiguousAliasesTypeId M1 = AnyAmbiguousAliasesTypeId._(1);
|
||||
static const AnyAmbiguousAliasesTypeId M2 = AnyAmbiguousAliasesTypeId._(2);
|
||||
static const AnyAmbiguousAliasesTypeId M3 = AnyAmbiguousAliasesTypeId._(3);
|
||||
static const Map<int, AnyAmbiguousAliasesTypeId> values = {
|
||||
0: NONE,
|
||||
1: M1,
|
||||
2: M2,
|
||||
3: M3};
|
||||
|
||||
static const fb.Reader<AnyAmbiguousAliasesTypeId> reader = _AnyAmbiguousAliasesTypeIdReader();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AnyAmbiguousAliasesTypeId{value: $value}';
|
||||
}
|
||||
}
|
||||
|
||||
class _AnyAmbiguousAliasesTypeIdReader extends fb.Reader<AnyAmbiguousAliasesTypeId> {
|
||||
@@ -1461,7 +1392,7 @@ class MonsterT implements fb.Packable {
|
||||
this.testrequirednestedflatbuffer,
|
||||
this.scalarKeySortedTables,
|
||||
this.nativeInline,
|
||||
this.longEnumNonEnumDefault = const LongEnum._(0),
|
||||
this.longEnumNonEnumDefault = LongEnum._default,
|
||||
this.longEnumNormalDefault = LongEnum.LongOne,
|
||||
this.nanDefault = double.nan,
|
||||
this.infDefault = double.infinity,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||
|
||||
library my_game;
|
||||
|
||||
|
||||
@@ -96,10 +96,10 @@ Additional options:
|
||||
|
||||
- `--scoped-enums` : Use C++11 style scoped and strongly typed enums in
|
||||
generated C++. This also implies `--no-prefix`.
|
||||
|
||||
|
||||
- `--no-emit-min-max-enum-values` : Disable generation of MIN and MAX
|
||||
enumerated values for scoped enums and prefixed enums.
|
||||
|
||||
|
||||
- `--gen-includes` : (deprecated), this is the default behavior.
|
||||
If the original behavior is required (no include
|
||||
statements) use `--no-includes.`
|
||||
@@ -238,5 +238,44 @@ Additional options:
|
||||
|
||||
- `--python-typing` : Generate Python type annotations
|
||||
|
||||
Additional gRPC options:
|
||||
|
||||
- `--grpc-filename-suffix`: `[C++]` An optional suffix for the generated
|
||||
files' names. For example, compiling gRPC for C++ with
|
||||
`--grpc-filename-suffix=.fbs` will generate `{name}.fbs.h` and
|
||||
`{name}.fbs.cc` files.
|
||||
|
||||
- `--grpc-additional-header`: `[C++]` Additional headers to include in the
|
||||
generated files.
|
||||
|
||||
- `--grpc-search-path`: `[C++]` An optional prefix for the gRPC runtime path.
|
||||
For example, compiling gRPC for C++ with `--grpc-search-path=some/path` will
|
||||
generate the following includes:
|
||||
|
||||
```cpp
|
||||
#include "some/path/grpcpp/impl/codegen/async_stream.h"
|
||||
#include "some/path/grpcpp/impl/codegen/async_unary_call.h"
|
||||
#include "some/path/grpcpp/impl/codegen/method_handler.h"
|
||||
...
|
||||
```
|
||||
|
||||
- `--grpc-use-system-headers`: `[C++]` Whether to generate `#include <header>`
|
||||
instead of `#include "header.h"` for all headers when compiling gRPC for
|
||||
C++. For example, compiling gRPC for C++ with `--grpc-use-system-headers`
|
||||
will generate the following includes:
|
||||
|
||||
```cpp
|
||||
#include <some/path/grpcpp/impl/codegen/async_stream.h>
|
||||
#include <some/path/grpcpp/impl/codegen/async_unary_call.h>
|
||||
#include <some/path/grpcpp/impl/codegen/method_handler.h>
|
||||
...
|
||||
```
|
||||
|
||||
NOTE: This option can be negated with `--no-grpc-use-system-headers`.
|
||||
|
||||
- `--grpc-python-typed-handlers`: `[Python]` Whether to generate the typed
|
||||
handlers that use the generated Python classes instead of raw bytes for
|
||||
requests/responses.
|
||||
|
||||
NOTE: short-form options for generators are deprecated, use the long form
|
||||
whenever possible.
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 24 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 3 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 7,
|
||||
FLATBUFFERS_VERSION_MINOR == 12 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 23,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
@@ -13,7 +13,7 @@ public struct Galaxy : IFlatbufferObject
|
||||
{
|
||||
private Table __p;
|
||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_24_3_7(); }
|
||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_24_12_23(); }
|
||||
public static Galaxy GetRootAsGalaxy(ByteBuffer _bb) { return GetRootAsGalaxy(_bb, new Galaxy()); }
|
||||
public static Galaxy GetRootAsGalaxy(ByteBuffer _bb, Galaxy obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); }
|
||||
|
||||
@@ -13,7 +13,7 @@ public struct Universe : IFlatbufferObject
|
||||
{
|
||||
private Table __p;
|
||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_24_3_7(); }
|
||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_24_12_23(); }
|
||||
public static Universe GetRootAsUniverse(ByteBuffer _bb) { return GetRootAsUniverse(_bb, new Universe()); }
|
||||
public static Universe GetRootAsUniverse(ByteBuffer _bb, Universe obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
||||
public static bool VerifyUniverse(ByteBuffer _bb) {Google.FlatBuffers.Verifier verifier = new Google.FlatBuffers.Verifier(_bb); return verifier.VerifyBuffer("", false, UniverseVerify.Verify); }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||
|
||||
library flatbuffers.goldens;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Galaxy extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_7(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_12_23(); }
|
||||
public static Galaxy getRootAsGalaxy(ByteBuffer _bb) { return getRootAsGalaxy(_bb, new Galaxy()); }
|
||||
public static Galaxy getRootAsGalaxy(ByteBuffer _bb, Galaxy 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); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Universe extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_7(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_12_23(); }
|
||||
public static Universe getRootAsUniverse(ByteBuffer _bb) { return getRootAsUniverse(_bb, new Universe()); }
|
||||
public static Universe getRootAsUniverse(ByteBuffer _bb, Universe 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); }
|
||||
|
||||
@@ -34,7 +34,7 @@ class Galaxy : Table() {
|
||||
return if(o != 0) bb.getLong(o + bb_pos) else 0L
|
||||
}
|
||||
companion object {
|
||||
fun validateVersion() = Constants.FLATBUFFERS_24_3_7()
|
||||
fun validateVersion() = Constants.FLATBUFFERS_24_12_23()
|
||||
fun getRootAsGalaxy(_bb: ByteBuffer): Galaxy = getRootAsGalaxy(_bb, Galaxy())
|
||||
fun getRootAsGalaxy(_bb: ByteBuffer, obj: Galaxy): Galaxy {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
|
||||
@@ -47,7 +47,7 @@ class Universe : Table() {
|
||||
val o = __offset(6); return if (o != 0) __vector_len(o) else 0
|
||||
}
|
||||
companion object {
|
||||
fun validateVersion() = Constants.FLATBUFFERS_24_3_7()
|
||||
fun validateVersion() = Constants.FLATBUFFERS_24_12_23()
|
||||
fun getRootAsUniverse(_bb: ByteBuffer): Universe = getRootAsUniverse(_bb, Universe())
|
||||
fun getRootAsUniverse(_bb: ByteBuffer, obj: Universe): Universe {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
|
||||
0
goldens/swift/__init__.py
Normal file
0
goldens/swift/__init__.py
Normal file
@@ -6,7 +6,7 @@ import FlatBuffers
|
||||
|
||||
public struct flatbuffers_goldens_Galaxy: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_24_3_7() }
|
||||
static func validateVersion() { FlatBuffersVersion_24_12_23() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
@@ -41,7 +41,7 @@ public struct flatbuffers_goldens_Galaxy: FlatBufferObject, Verifiable {
|
||||
|
||||
public struct flatbuffers_goldens_Universe: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_24_3_7() }
|
||||
static func validateVersion() { FlatBuffersVersion_24_12_23() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
|
||||
@@ -11,3 +11,31 @@ index 1645a264a..12f8ca999 100644
|
||||
add_executable(
|
||||
bssl
|
||||
|
||||
diff --git a/src/crypto/x509/t_x509.c b/src/crypto/x509/t_x509.c
|
||||
index 7c32a8798..6e50d040e 100644
|
||||
--- a/src/crypto/x509/t_x509.c
|
||||
+++ b/src/crypto/x509/t_x509.c
|
||||
@@ -318,9 +318,7 @@ int X509_signature_print(BIO *bp, const X509_ALGOR *sigalg,
|
||||
int X509_NAME_print(BIO *bp, const X509_NAME *name, int obase)
|
||||
{
|
||||
char *s, *c, *b;
|
||||
- int ret = 0, l, i;
|
||||
-
|
||||
- l = 80 - 2 - obase;
|
||||
+ int ret = 0, i;
|
||||
|
||||
b = X509_NAME_oneline(name, NULL, 0);
|
||||
if (!b)
|
||||
@@ -347,12 +345,10 @@ int X509_NAME_print(BIO *bp, const X509_NAME *name, int obase)
|
||||
if (BIO_write(bp, ", ", 2) != 2)
|
||||
goto err;
|
||||
}
|
||||
- l--;
|
||||
}
|
||||
if (*s == '\0')
|
||||
break;
|
||||
s++;
|
||||
- l--;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
@@ -2,9 +2,12 @@ diff --git a/bazel/copts.bzl b/bazel/copts.bzl
|
||||
index 10be944f25..879518b92f 100644
|
||||
--- a/bazel/copts.bzl
|
||||
+++ b/bazel/copts.bzl
|
||||
@@ -59,4 +59,4 @@ GRPC_LLVM_WARNING_FLAGS = [
|
||||
@@ -59,4 +59,7 @@ GRPC_LLVM_WARNING_FLAGS = [
|
||||
GRPC_DEFAULT_COPTS = select({
|
||||
"//:use_strict_warning": GRPC_LLVM_WARNING_FLAGS + ["-DUSE_STRICT_WARNING=1"],
|
||||
"//conditions:default": [],
|
||||
-})
|
||||
+}) + ["-std=c++14"]
|
||||
+}) + select({
|
||||
+ "@bazel_tools//src/conditions:windows": ["/std:c++14"],
|
||||
+ "//conditions:default": ["-std=c++14"],
|
||||
+})
|
||||
|
||||
54
grpc/examples/python/greeter/greeter_grpc.fb.py
Normal file
54
grpc/examples/python/greeter/greeter_grpc.fb.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# Generated by the gRPC FlatBuffers compiler. DO NOT EDIT!
|
||||
|
||||
import flatbuffers
|
||||
import grpc
|
||||
|
||||
from models.HelloReply import HelloReply
|
||||
from models.HelloRequest import HelloRequest
|
||||
|
||||
|
||||
class GreeterStub(object):
|
||||
'''Interface exported by the server.'''
|
||||
|
||||
def __init__(self, channel):
|
||||
'''Constructor.
|
||||
|
||||
Args:
|
||||
channel: A grpc.Channel.
|
||||
'''
|
||||
|
||||
self.SayHello = channel.unary_unary(
|
||||
method='/models.Greeter/SayHello')
|
||||
|
||||
self.SayManyHellos = channel.unary_stream(
|
||||
method='/models.Greeter/SayManyHellos')
|
||||
|
||||
|
||||
class GreeterServicer(object):
|
||||
'''Interface exported by the server.'''
|
||||
|
||||
def SayHello(self, request, context):
|
||||
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
||||
context.set_details('Method not implemented!')
|
||||
raise NotImplementedError('Method not implemented!')
|
||||
|
||||
def SayManyHellos(self, request, context):
|
||||
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
||||
context.set_details('Method not implemented!')
|
||||
raise NotImplementedError('Method not implemented!')
|
||||
|
||||
|
||||
def add_GreeterServicer_to_server(servicer, server):
|
||||
rpc_method_handlers = {
|
||||
'SayHello': grpc.unary_unary_rpc_method_handler(
|
||||
servicer.SayHello),
|
||||
'SayManyHellos': grpc.unary_stream_rpc_method_handler(
|
||||
servicer.SayManyHellos),
|
||||
}
|
||||
|
||||
generic_handler = grpc.method_handlers_generic_handler(
|
||||
'models.Greeter', rpc_method_handlers)
|
||||
|
||||
server.add_generic_rpc_handlers((generic_handler,))
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import FlatBuffers
|
||||
|
||||
public struct models_HelloReply: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_24_3_7() }
|
||||
static func validateVersion() { FlatBuffersVersion_24_12_23() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
@@ -53,7 +53,7 @@ extension models_HelloReply: Encodable {
|
||||
|
||||
public struct models_HelloRequest: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_24_3_7() }
|
||||
static func validateVersion() { FlatBuffersVersion_24_12_23() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
* Copyright 2024 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
* Copyright 2024 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
</developer>
|
||||
</developers>
|
||||
<properties>
|
||||
<gRPC.version>1.36.0</gRPC.version>
|
||||
<gRPC.version>1.67.1</gRPC.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@@ -95,6 +95,8 @@ cc_library(
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
"//:flatbuffers",
|
||||
"//include/codegen:namer",
|
||||
"//include/codegen:python",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
namespace grpc_cpp_generator {
|
||||
namespace {
|
||||
|
||||
static grpc::string service_header_ext() { return ".grpc.fb.h"; }
|
||||
|
||||
template<class T>
|
||||
static grpc::string as_string(T x) {
|
||||
std::ostringstream out;
|
||||
@@ -1137,7 +1135,7 @@ grpc::string GetSourcePrologue(grpc_generator::File *file,
|
||||
vars["filename"] = file->filename();
|
||||
vars["filename_base"] = file->filename_without_ext();
|
||||
vars["message_header_ext"] = params.message_header_extension;
|
||||
vars["service_header_ext"] = service_header_ext();
|
||||
vars["service_header_ext"] = params.service_header_extension;
|
||||
|
||||
printer->Print(vars, "// Generated by the gRPC C++ plugin.\n");
|
||||
printer->Print(vars,
|
||||
@@ -1557,7 +1555,7 @@ grpc::string GetMockPrologue(grpc_generator::File *file,
|
||||
vars["filename"] = file->filename();
|
||||
vars["filename_base"] = file->filename_without_ext();
|
||||
vars["message_header_ext"] = params.message_header_extension;
|
||||
vars["service_header_ext"] = service_header_ext();
|
||||
vars["service_header_ext"] = params.service_header_extension;
|
||||
|
||||
printer->Print(vars, "// Generated by the gRPC C++ plugin.\n");
|
||||
printer->Print(vars,
|
||||
|
||||
@@ -35,6 +35,8 @@ struct Parameters {
|
||||
bool generate_mock_code;
|
||||
// By default, use "_generated.h"
|
||||
std::string message_header_extension;
|
||||
// Default: ".grpc.fb.h"
|
||||
std::string service_header_extension;
|
||||
};
|
||||
|
||||
// Return the prologue of the generated header file.
|
||||
|
||||
@@ -16,136 +16,365 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
|
||||
#include "flatbuffers/util.h"
|
||||
#include "src/compiler/python_generator.h"
|
||||
|
||||
namespace grpc_python_generator {
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "codegen/idl_namer.h"
|
||||
#include "codegen/namer.h"
|
||||
#include "codegen/python.h"
|
||||
#include "flatbuffers/idl.h"
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
namespace python {
|
||||
namespace grpc {
|
||||
namespace {
|
||||
|
||||
static grpc::string GenerateMethodType(const grpc_generator::Method *method) {
|
||||
|
||||
if (method->NoStreaming())
|
||||
return "unary_unary";
|
||||
|
||||
if (method->ServerStreaming())
|
||||
return "unary_stream";
|
||||
|
||||
if (method->ClientStreaming())
|
||||
return "stream_unary";
|
||||
|
||||
return "stream_stream";
|
||||
bool ClientStreaming(const RPCCall *method) {
|
||||
const Value *val = method->attributes.Lookup("streaming");
|
||||
return val != nullptr && (val->constant == "client" || val->constant == "bidi");
|
||||
}
|
||||
|
||||
grpc::string GenerateMethodInput(const grpc_generator::Method *method) {
|
||||
|
||||
if (method->NoStreaming() || method->ServerStreaming())
|
||||
return "self, request, context";
|
||||
|
||||
return "self, request_iterator, context";
|
||||
bool ServerStreaming(const RPCCall *method) {
|
||||
const Value *val = method->attributes.Lookup("streaming");
|
||||
return val != nullptr && (val->constant == "server" || val->constant == "bidi");
|
||||
}
|
||||
|
||||
void GenerateStub(const grpc_generator::Service *service,
|
||||
grpc_generator::Printer *printer,
|
||||
std::map<grpc::string, grpc::string> *dictonary) {
|
||||
auto vars = *dictonary;
|
||||
printer->Print(vars, "class $ServiceName$Stub(object):\n");
|
||||
printer->Indent();
|
||||
printer->Print("\"\"\" Interface exported by the server. \"\"\"");
|
||||
printer->Print("\n\n");
|
||||
printer->Print("def __init__(self, channel):\n");
|
||||
printer->Indent();
|
||||
printer->Print("\"\"\" Constructor. \n\n");
|
||||
printer->Print("Args: \n");
|
||||
printer->Print("channel: A grpc.Channel. \n");
|
||||
printer->Print("\"\"\"\n\n");
|
||||
|
||||
for (int j = 0; j < service->method_count(); j++) {
|
||||
auto method = service->method(j);
|
||||
vars["MethodName"] = method->name();
|
||||
vars["MethodType"] = GenerateMethodType(&*method);
|
||||
printer->Print(vars, "self.$MethodName$ = channel.$MethodType$(\n");
|
||||
printer->Indent();
|
||||
printer->Print(vars, "\"/$PATH$$ServiceName$/$MethodName$\"\n");
|
||||
printer->Print(")\n");
|
||||
printer->Outdent();
|
||||
printer->Print("\n");
|
||||
void FormatImports(std::stringstream &ss, const Imports &imports) {
|
||||
std::set<std::string> modules;
|
||||
std::map<std::string, std::set<std::string>> names_by_module;
|
||||
for (const Import &import : imports.imports) {
|
||||
if (import.IsLocal()) continue; // skip all local imports
|
||||
if (import.name == "") {
|
||||
modules.insert(import.module);
|
||||
} else {
|
||||
names_by_module[import.module].insert(import.name);
|
||||
}
|
||||
}
|
||||
printer->Outdent();
|
||||
printer->Outdent();
|
||||
printer->Print("\n");
|
||||
}
|
||||
|
||||
void GenerateServicer(const grpc_generator::Service *service,
|
||||
grpc_generator::Printer *printer,
|
||||
std::map<grpc::string, grpc::string> *dictonary) {
|
||||
auto vars = *dictonary;
|
||||
printer->Print(vars, "class $ServiceName$Servicer(object):\n");
|
||||
printer->Indent();
|
||||
printer->Print("\"\"\" Interface exported by the server. \"\"\"");
|
||||
printer->Print("\n\n");
|
||||
|
||||
for (int j = 0; j < service->method_count(); j++) {
|
||||
auto method = service->method(j);
|
||||
vars["MethodName"] = method->name();
|
||||
vars["MethodInput"] = GenerateMethodInput(&*method);
|
||||
printer->Print(vars, "def $MethodName$($MethodInput$):\n");
|
||||
printer->Indent();
|
||||
printer->Print("context.set_code(grpc.StatusCode.UNIMPLEMENTED)\n");
|
||||
printer->Print("context.set_details('Method not implemented!')\n");
|
||||
printer->Print("raise NotImplementedError('Method not implemented!')\n");
|
||||
printer->Outdent();
|
||||
printer->Print("\n\n");
|
||||
for (const std::string &module : modules) {
|
||||
ss << "import " << module << '\n';
|
||||
}
|
||||
printer->Outdent();
|
||||
printer->Print("\n");
|
||||
|
||||
}
|
||||
|
||||
void GenerateRegister(const grpc_generator::Service *service,
|
||||
grpc_generator::Printer *printer,
|
||||
std::map<grpc::string, grpc::string> *dictonary) {
|
||||
auto vars = *dictonary;
|
||||
printer->Print(vars, "def add_$ServiceName$Servicer_to_server(servicer, server):\n");
|
||||
printer->Indent();
|
||||
printer->Print("rpc_method_handlers = {\n");
|
||||
printer->Indent();
|
||||
for (int j = 0; j < service->method_count(); j++) {
|
||||
auto method = service->method(j);
|
||||
vars["MethodName"] = method->name();
|
||||
vars["MethodType"] = GenerateMethodType(&*method);
|
||||
printer->Print(vars, "'$MethodName$': grpc.$MethodType$_rpc_method_handler(\n");
|
||||
printer->Indent();
|
||||
printer->Print(vars, "servicer.$MethodName$\n");
|
||||
printer->Outdent();
|
||||
printer->Print("),\n");
|
||||
ss << '\n';
|
||||
for (const auto &import : names_by_module) {
|
||||
ss << "from " << import.first << " import ";
|
||||
size_t i = 0;
|
||||
for (const std::string &name : import.second) {
|
||||
if (i > 0) ss << ", ";
|
||||
ss << name;
|
||||
++i;
|
||||
}
|
||||
ss << '\n';
|
||||
}
|
||||
printer->Outdent();
|
||||
printer->Print("}\n");
|
||||
printer->Print(vars, "generic_handler = grpc.method_handlers_generic_handler(\n");
|
||||
printer->Indent();
|
||||
printer->Print(vars, "'$PATH$$ServiceName$', rpc_method_handlers)\n");
|
||||
printer->Outdent();
|
||||
printer->Print("server.add_generic_rpc_handlers((generic_handler,))");
|
||||
printer->Outdent();
|
||||
printer->Print("\n");
|
||||
}
|
||||
} // namespace
|
||||
|
||||
grpc::string Generate(grpc_generator::File *file,
|
||||
const grpc_generator::Service *service) {
|
||||
grpc::string output;
|
||||
std::map<grpc::string, grpc::string> vars;
|
||||
vars["PATH"] = file->package();
|
||||
if (!file->package().empty()) { vars["PATH"].append("."); }
|
||||
vars["ServiceName"] = service->name();
|
||||
auto printer = file->CreatePrinter(&output);
|
||||
GenerateStub(service, &*printer, &vars);
|
||||
GenerateServicer(service, &*printer, &vars);
|
||||
GenerateRegister(service, &*printer, &vars);
|
||||
return output;
|
||||
ss << "\n\n";
|
||||
}
|
||||
|
||||
} // namespace grpc_python_generator
|
||||
bool SaveStub(const std::string &filename, const Imports &imports,
|
||||
const std::string &content) {
|
||||
std::stringstream ss;
|
||||
ss << "# Generated by the gRPC FlatBuffers compiler. DO NOT EDIT!\n"
|
||||
<< '\n'
|
||||
<< "from __future__ import annotations\n"
|
||||
<< '\n';
|
||||
FormatImports(ss, imports);
|
||||
ss << content << '\n';
|
||||
|
||||
EnsureDirExists(StripFileName(filename));
|
||||
return flatbuffers::SaveFile(filename.c_str(), ss.str(), false);
|
||||
}
|
||||
|
||||
bool SaveService(const std::string &filename, const Imports &imports,
|
||||
const std::string &content) {
|
||||
std::stringstream ss;
|
||||
ss << "# Generated by the gRPC FlatBuffers compiler. DO NOT EDIT!\n" << '\n';
|
||||
FormatImports(ss, imports);
|
||||
ss << content << '\n';
|
||||
|
||||
EnsureDirExists(StripFileName(filename));
|
||||
return flatbuffers::SaveFile(filename.c_str(), ss.str(), false);
|
||||
}
|
||||
|
||||
class BaseGenerator {
|
||||
protected:
|
||||
BaseGenerator(const Parser &parser, const Namer::Config &config,
|
||||
const std::string &path, const Version &version)
|
||||
: parser_{parser},
|
||||
namer_{WithFlagOptions(config, parser.opts, path), Keywords(version)},
|
||||
version_{version} {}
|
||||
|
||||
protected:
|
||||
std::string ModuleForFile(const std::string &file) const {
|
||||
std::string module = parser_.opts.include_prefix + StripExtension(file) +
|
||||
parser_.opts.filename_suffix;
|
||||
std::replace(module.begin(), module.end(), '/', '.');
|
||||
return module;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string ModuleFor(const T *def) const {
|
||||
if (parser_.opts.one_file) return ModuleForFile(def->file);
|
||||
return namer_.NamespacedType(*def);
|
||||
}
|
||||
|
||||
const Parser &parser_;
|
||||
const IdlNamer namer_;
|
||||
const Version version_;
|
||||
};
|
||||
|
||||
class StubGenerator : public BaseGenerator {
|
||||
public:
|
||||
StubGenerator(const Parser &parser, const std::string &path,
|
||||
const Version &version)
|
||||
: BaseGenerator(parser, kStubConfig, path, version) {}
|
||||
|
||||
bool Generate() {
|
||||
Imports imports;
|
||||
std::stringstream stub;
|
||||
for (const ServiceDef *service : parser_.services_.vec) {
|
||||
Generate(stub, service, &imports);
|
||||
}
|
||||
|
||||
std::string filename =
|
||||
namer_.config_.output_path +
|
||||
StripPath(StripExtension(parser_.file_being_parsed_)) + "_grpc" +
|
||||
parser_.opts.grpc_filename_suffix + namer_.config_.filename_extension;
|
||||
|
||||
return SaveStub(filename, imports, stub.str());
|
||||
}
|
||||
|
||||
private:
|
||||
void Generate(std::stringstream &ss, const ServiceDef *service,
|
||||
Imports *imports) {
|
||||
imports->Import("grpc");
|
||||
|
||||
ss << "class " << service->name << "Stub(object):\n"
|
||||
<< " def __init__(self, channel: grpc.Channel) -> None: ...\n";
|
||||
|
||||
for (const RPCCall *method : service->calls.vec) {
|
||||
std::string request = "bytes";
|
||||
std::string response = "bytes";
|
||||
|
||||
if (parser_.opts.grpc_python_typed_handlers) {
|
||||
request = namer_.Type(*method->request);
|
||||
response = namer_.Type(*method->response);
|
||||
|
||||
imports->Import(ModuleFor(method->request), request);
|
||||
imports->Import(ModuleFor(method->response), response);
|
||||
}
|
||||
|
||||
ss << " def " << method->name << "(self, ";
|
||||
if (ClientStreaming(method)) {
|
||||
imports->Import("typing");
|
||||
ss << "request_iterator: typing.Iterator[" << request << "]";
|
||||
} else {
|
||||
ss << "request: " << request;
|
||||
}
|
||||
ss << ") -> ";
|
||||
if (ServerStreaming(method)) {
|
||||
imports->Import("typing");
|
||||
ss << "typing.Iterator[" << response << "]";
|
||||
} else {
|
||||
ss << response;
|
||||
}
|
||||
ss << ": ...\n";
|
||||
}
|
||||
|
||||
ss << "\n\n";
|
||||
ss << "class " << service->name << "Servicer(object):\n";
|
||||
|
||||
for (const RPCCall *method : service->calls.vec) {
|
||||
std::string request = "bytes";
|
||||
std::string response = "bytes";
|
||||
|
||||
if (parser_.opts.grpc_python_typed_handlers) {
|
||||
request = namer_.Type(*method->request);
|
||||
response = namer_.Type(*method->response);
|
||||
|
||||
imports->Import(ModuleFor(method->request), request);
|
||||
imports->Import(ModuleFor(method->response), response);
|
||||
}
|
||||
|
||||
ss << " def " << method->name << "(self, ";
|
||||
if (ClientStreaming(method)) {
|
||||
imports->Import("typing");
|
||||
ss << "request_iterator: typing.Iterator[" << request << "]";
|
||||
} else {
|
||||
ss << "request: " << request;
|
||||
}
|
||||
ss << ", context: grpc.ServicerContext) -> ";
|
||||
if (ServerStreaming(method)) {
|
||||
imports->Import("typing");
|
||||
ss << "typing.Iterator[" << response << "]";
|
||||
} else {
|
||||
ss << response;
|
||||
}
|
||||
ss << ": ...\n";
|
||||
}
|
||||
|
||||
ss << '\n'
|
||||
<< '\n'
|
||||
<< "def add_" << service->name
|
||||
<< "Servicer_to_server(servicer: " << service->name
|
||||
<< "Servicer, server: grpc.Server) -> None: ...\n";
|
||||
}
|
||||
};
|
||||
|
||||
class ServiceGenerator : public BaseGenerator {
|
||||
public:
|
||||
ServiceGenerator(const Parser &parser, const std::string &path,
|
||||
const Version &version)
|
||||
: BaseGenerator(parser, kConfig, path, version) {}
|
||||
|
||||
bool Generate() {
|
||||
Imports imports;
|
||||
std::stringstream ss;
|
||||
|
||||
imports.Import("flatbuffers");
|
||||
|
||||
if (parser_.opts.grpc_python_typed_handlers) {
|
||||
ss << "def _serialize_to_bytes(table):\n"
|
||||
<< " buf = table._tab.Bytes\n"
|
||||
<< " n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)\n"
|
||||
<< " if table._tab.Pos != n:\n"
|
||||
<< " raise ValueError('must be a top-level table')\n"
|
||||
<< " return bytes(buf)\n"
|
||||
<< '\n'
|
||||
<< '\n';
|
||||
}
|
||||
|
||||
for (const ServiceDef *service : parser_.services_.vec) {
|
||||
GenerateStub(ss, service, &imports);
|
||||
GenerateServicer(ss, service, &imports);
|
||||
GenerateRegister(ss, service, &imports);
|
||||
}
|
||||
|
||||
std::string filename =
|
||||
namer_.config_.output_path +
|
||||
StripPath(StripExtension(parser_.file_being_parsed_)) + "_grpc" +
|
||||
parser_.opts.grpc_filename_suffix + namer_.config_.filename_extension;
|
||||
|
||||
return SaveService(filename, imports, ss.str());
|
||||
}
|
||||
|
||||
private:
|
||||
void GenerateStub(std::stringstream &ss, const ServiceDef *service,
|
||||
Imports *imports) {
|
||||
ss << "class " << service->name << "Stub";
|
||||
if (version_.major != 3) ss << "(object)";
|
||||
ss << ":\n"
|
||||
<< " '''Interface exported by the server.'''\n"
|
||||
<< '\n'
|
||||
<< " def __init__(self, channel):\n"
|
||||
<< " '''Constructor.\n"
|
||||
<< '\n'
|
||||
<< " Args:\n"
|
||||
<< " channel: A grpc.Channel.\n"
|
||||
<< " '''\n"
|
||||
<< '\n';
|
||||
|
||||
for (const RPCCall *method : service->calls.vec) {
|
||||
std::string response = namer_.Type(*method->response);
|
||||
|
||||
imports->Import(ModuleFor(method->response), response);
|
||||
|
||||
ss << " self." << method->name << " = channel."
|
||||
<< (ClientStreaming(method) ? "stream" : "unary") << "_"
|
||||
<< (ServerStreaming(method) ? "stream" : "unary") << "(\n"
|
||||
<< " method='/"
|
||||
<< service->defined_namespace->GetFullyQualifiedName(service->name)
|
||||
<< "/" << method->name << "'";
|
||||
|
||||
if (parser_.opts.grpc_python_typed_handlers) {
|
||||
ss << ",\n"
|
||||
<< " request_serializer=_serialize_to_bytes,\n"
|
||||
<< " response_deserializer=" << response << ".GetRootAs";
|
||||
}
|
||||
ss << ")\n\n";
|
||||
}
|
||||
|
||||
ss << '\n';
|
||||
}
|
||||
|
||||
void GenerateServicer(std::stringstream &ss, const ServiceDef *service,
|
||||
Imports *imports) {
|
||||
imports->Import("grpc");
|
||||
|
||||
ss << "class " << service->name << "Servicer";
|
||||
if (version_.major != 3) ss << "(object)";
|
||||
ss << ":\n"
|
||||
<< " '''Interface exported by the server.'''\n"
|
||||
<< '\n';
|
||||
|
||||
for (const RPCCall *method : service->calls.vec) {
|
||||
const std::string request_param =
|
||||
ClientStreaming(method) ? "request_iterator" : "request";
|
||||
ss << " def " << method->name << "(self, " << request_param
|
||||
<< ", context):\n"
|
||||
<< " context.set_code(grpc.StatusCode.UNIMPLEMENTED)\n"
|
||||
<< " context.set_details('Method not implemented!')\n"
|
||||
<< " raise NotImplementedError('Method not implemented!')\n"
|
||||
<< '\n';
|
||||
}
|
||||
|
||||
ss << '\n';
|
||||
}
|
||||
|
||||
void GenerateRegister(std::stringstream &ss, const ServiceDef *service,
|
||||
Imports *imports) {
|
||||
imports->Import("grpc");
|
||||
|
||||
ss << "def add_" << service->name
|
||||
<< "Servicer_to_server(servicer, server):\n"
|
||||
<< " rpc_method_handlers = {\n";
|
||||
|
||||
for (const RPCCall *method : service->calls.vec) {
|
||||
std::string request = namer_.Type(*method->request);
|
||||
|
||||
imports->Import(ModuleFor(method->request), request);
|
||||
|
||||
ss << " '" << method->name << "': grpc."
|
||||
<< (ClientStreaming(method) ? "stream" : "unary") << "_"
|
||||
<< (ServerStreaming(method) ? "stream" : "unary")
|
||||
<< "_rpc_method_handler(\n"
|
||||
<< " servicer." << method->name;
|
||||
|
||||
if (parser_.opts.grpc_python_typed_handlers) {
|
||||
ss << ",\n"
|
||||
<< " request_deserializer=" << request << ".GetRootAs,\n"
|
||||
<< " response_serializer=_serialize_to_bytes";
|
||||
}
|
||||
ss << "),\n";
|
||||
}
|
||||
ss << " }\n"
|
||||
<< '\n'
|
||||
<< " generic_handler = grpc.method_handlers_generic_handler(\n"
|
||||
<< " '"
|
||||
<< service->defined_namespace->GetFullyQualifiedName(service->name)
|
||||
<< "', rpc_method_handlers)\n"
|
||||
<< '\n'
|
||||
<< " server.add_generic_rpc_handlers((generic_handler,))\n"
|
||||
<< '\n';
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
bool Generate(const Parser &parser, const std::string &path,
|
||||
const Version &version) {
|
||||
ServiceGenerator generator{parser, path, version};
|
||||
return generator.Generate();
|
||||
}
|
||||
|
||||
bool GenerateStub(const Parser &parser, const std::string &path,
|
||||
const Version &version) {
|
||||
StubGenerator generator{parser, path, version};
|
||||
return generator.Generate();
|
||||
}
|
||||
|
||||
} // namespace grpc
|
||||
} // namespace python
|
||||
} // namespace flatbuffers
|
||||
|
||||
@@ -19,14 +19,21 @@
|
||||
#ifndef GRPC_INTERNAL_COMPILER_PYTHON_GENERATOR_H
|
||||
#define GRPC_INTERNAL_COMPILER_PYTHON_GENERATOR_H
|
||||
|
||||
#include <utility>
|
||||
#include <string>
|
||||
|
||||
#include "src/compiler/schema_interface.h"
|
||||
#include "codegen/python.h"
|
||||
#include "flatbuffers/idl.h"
|
||||
|
||||
namespace grpc_python_generator {
|
||||
namespace flatbuffers {
|
||||
namespace python {
|
||||
namespace grpc {
|
||||
bool Generate(const Parser &parser, const std::string &path,
|
||||
const Version &version);
|
||||
|
||||
grpc::string Generate(grpc_generator::File *file,
|
||||
const grpc_generator::Service *service);
|
||||
} // namespace grpc_python_generator
|
||||
bool GenerateStub(const Parser &parser, const std::string &path,
|
||||
const Version &version);
|
||||
} // namespace grpc
|
||||
} // namespace python
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // GRPC_INTERNAL_COMPILER_PYTHON_GENERATOR_H
|
||||
|
||||
39
include/codegen/BUILD.bazel
Normal file
39
include/codegen/BUILD.bazel
Normal file
@@ -0,0 +1,39 @@
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
package(
|
||||
default_visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "distribution",
|
||||
srcs = [
|
||||
"BUILD.bazel",
|
||||
] + glob([
|
||||
"*.cc",
|
||||
"*.h",
|
||||
]),
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "namer",
|
||||
hdrs = [
|
||||
"idl_namer.h",
|
||||
"namer.h",
|
||||
],
|
||||
strip_include_prefix = "/include",
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = ["//:runtime_cc"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "python",
|
||||
srcs = ["python.cc"],
|
||||
hdrs = ["python.h"],
|
||||
strip_include_prefix = "/include",
|
||||
visibility = [
|
||||
"//grpc:__subpackages__",
|
||||
"//src:__subpackages__",
|
||||
],
|
||||
deps = [":namer"],
|
||||
)
|
||||
179
include/codegen/idl_namer.h
Normal file
179
include/codegen/idl_namer.h
Normal file
@@ -0,0 +1,179 @@
|
||||
#ifndef FLATBUFFERS_INCLUDE_CODEGEN_IDL_NAMER_H_
|
||||
#define FLATBUFFERS_INCLUDE_CODEGEN_IDL_NAMER_H_
|
||||
|
||||
#include "codegen/namer.h"
|
||||
#include "flatbuffers/idl.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
// Provides Namer capabilities to types defined in the flatbuffers IDL.
|
||||
class IdlNamer : public Namer {
|
||||
public:
|
||||
explicit IdlNamer(Config config, std::set<std::string> keywords)
|
||||
: Namer(config, std::move(keywords)) {}
|
||||
|
||||
using Namer::Constant;
|
||||
using Namer::Directories;
|
||||
using Namer::Field;
|
||||
using Namer::File;
|
||||
using Namer::Function;
|
||||
using Namer::Method;
|
||||
using Namer::Namespace;
|
||||
using Namer::NamespacedType;
|
||||
using Namer::ObjectType;
|
||||
using Namer::Type;
|
||||
using Namer::Variable;
|
||||
using Namer::Variant;
|
||||
|
||||
std::string Constant(const FieldDef &d) const { return Constant(d.name); }
|
||||
|
||||
// Types are always structs or enums so we can only expose these two
|
||||
// overloads.
|
||||
std::string Type(const StructDef &d) const { return Type(d.name); }
|
||||
std::string Type(const EnumDef &d) const { return Type(d.name); }
|
||||
|
||||
std::string Function(const Definition &s) const { return Function(s.name); }
|
||||
std::string Function(const std::string& prefix, const Definition &s) const {
|
||||
return Function(prefix + s.name);
|
||||
}
|
||||
|
||||
std::string Field(const FieldDef &s) const { return Field(s.name); }
|
||||
std::string Field(const FieldDef &d, const std::string &s) const {
|
||||
return Field(d.name + "_" + s);
|
||||
}
|
||||
|
||||
std::string Variable(const FieldDef &s) const { return Variable(s.name); }
|
||||
|
||||
std::string Variable(const StructDef &s) const { return Variable(s.name); }
|
||||
|
||||
std::string Variant(const EnumVal &s) const { return Variant(s.name); }
|
||||
|
||||
std::string EnumVariant(const EnumDef &e, const EnumVal &v) const {
|
||||
return Type(e) + config_.enum_variant_seperator + Variant(v);
|
||||
}
|
||||
|
||||
std::string ObjectType(const StructDef &d) const {
|
||||
return ObjectType(d.name);
|
||||
}
|
||||
std::string ObjectType(const EnumDef &d) const { return ObjectType(d.name); }
|
||||
|
||||
std::string Method(const FieldDef &d, const std::string &suffix) const {
|
||||
return Method(d.name, suffix);
|
||||
}
|
||||
std::string Method(const std::string &prefix, const StructDef &d) const {
|
||||
return Method(prefix, d.name);
|
||||
}
|
||||
std::string Method(const std::string &prefix, const FieldDef &d) const {
|
||||
return Method(prefix, d.name);
|
||||
}
|
||||
std::string Method(const std::string &prefix, const FieldDef &d,
|
||||
const std::string &suffix) const {
|
||||
return Method(prefix, d.name, suffix);
|
||||
}
|
||||
|
||||
std::string Namespace(const struct Namespace &ns) const {
|
||||
return Namespace(ns.components);
|
||||
}
|
||||
|
||||
std::string NamespacedEnumVariant(const EnumDef &e, const EnumVal &v) const {
|
||||
return NamespacedString(e.defined_namespace, EnumVariant(e, v));
|
||||
}
|
||||
|
||||
std::string NamespacedType(const Definition &def) const {
|
||||
return NamespacedString(def.defined_namespace, Type(def.name));
|
||||
}
|
||||
|
||||
std::string NamespacedObjectType(const Definition &def) const {
|
||||
return NamespacedString(def.defined_namespace, ObjectType(def.name));
|
||||
}
|
||||
|
||||
std::string Directories(const struct Namespace &ns,
|
||||
SkipDir skips = SkipDir::None,
|
||||
Case input_case = Case::kUpperCamel) const {
|
||||
return Directories(ns.components, skips, input_case);
|
||||
}
|
||||
|
||||
// Legacy fields do not really follow the usual config and should be
|
||||
// considered for deprecation.
|
||||
|
||||
std::string LegacyRustNativeVariant(const EnumVal &v) const {
|
||||
return ConvertCase(EscapeKeyword(v.name), Case::kUpperCamel);
|
||||
}
|
||||
|
||||
std::string LegacyRustFieldOffsetName(const FieldDef &field) const {
|
||||
return "VT_" + ConvertCase(EscapeKeyword(field.name), Case::kAllUpper);
|
||||
}
|
||||
std::string LegacyRustUnionTypeOffsetName(const FieldDef &field) const {
|
||||
return "VT_" + ConvertCase(EscapeKeyword(field.name + "_type"), Case::kAllUpper);
|
||||
}
|
||||
|
||||
|
||||
std::string LegacySwiftVariant(const EnumVal &ev) const {
|
||||
auto name = ev.name;
|
||||
if (isupper(name.front())) {
|
||||
std::transform(name.begin(), name.end(), name.begin(), CharToLower);
|
||||
}
|
||||
return EscapeKeyword(ConvertCase(name, Case::kLowerCamel));
|
||||
}
|
||||
|
||||
// Also used by Kotlin, lol.
|
||||
std::string LegacyJavaMethod2(const std::string &prefix, const StructDef &sd,
|
||||
const std::string &suffix) const {
|
||||
return prefix + sd.name + suffix;
|
||||
}
|
||||
|
||||
std::string LegacyKotlinVariant(EnumVal &ev) const {
|
||||
// Namer assumes the input case is snake case which is wrong...
|
||||
return ConvertCase(EscapeKeyword(ev.name), Case::kLowerCamel);
|
||||
}
|
||||
// Kotlin methods escapes keywords after case conversion but before
|
||||
// prefixing and suffixing.
|
||||
std::string LegacyKotlinMethod(const std::string &prefix, const FieldDef &d,
|
||||
const std::string &suffix) const {
|
||||
return prefix + ConvertCase(EscapeKeyword(d.name), Case::kUpperCamel) +
|
||||
suffix;
|
||||
}
|
||||
std::string LegacyKotlinMethod(const std::string &prefix, const StructDef &d,
|
||||
const std::string &suffix) const {
|
||||
return prefix + ConvertCase(EscapeKeyword(d.name), Case::kUpperCamel) +
|
||||
suffix;
|
||||
}
|
||||
|
||||
// This is a mix of snake case and keep casing, when Ts should be using
|
||||
// lower camel case.
|
||||
std::string LegacyTsMutateMethod(const FieldDef& d) {
|
||||
return "mutate_" + d.name;
|
||||
}
|
||||
|
||||
std::string LegacyRustUnionTypeMethod(const FieldDef &d) {
|
||||
// assert d is a union
|
||||
// d should convert case but not escape keywords due to historical reasons
|
||||
return ConvertCase(d.name, config_.fields, Case::kLowerCamel) + "_type";
|
||||
}
|
||||
|
||||
private:
|
||||
std::string NamespacedString(const struct Namespace *ns,
|
||||
const std::string &str) const {
|
||||
std::string ret;
|
||||
if (ns != nullptr) { ret += Namespace(ns->components); }
|
||||
if (!ret.empty()) ret += config_.namespace_seperator;
|
||||
return ret + str;
|
||||
}
|
||||
};
|
||||
|
||||
// This is a temporary helper function for code generators to call until all
|
||||
// flag-overriding logic into flatc.cpp
|
||||
inline Namer::Config WithFlagOptions(const Namer::Config &input,
|
||||
const IDLOptions &opts,
|
||||
const std::string &path) {
|
||||
Namer::Config result = input;
|
||||
result.object_prefix = opts.object_prefix;
|
||||
result.object_suffix = opts.object_suffix;
|
||||
result.output_path = path;
|
||||
result.filename_suffix = opts.filename_suffix;
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // FLATBUFFERS_INCLUDE_CODEGEN_IDL_NAMER_H_
|
||||
270
include/codegen/namer.h
Normal file
270
include/codegen/namer.h
Normal file
@@ -0,0 +1,270 @@
|
||||
#ifndef FLATBUFFERS_INCLUDE_CODEGEN_NAMER_H_
|
||||
#define FLATBUFFERS_INCLUDE_CODEGEN_NAMER_H_
|
||||
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
// Options for Namer::File.
|
||||
enum class SkipFile {
|
||||
None = 0,
|
||||
Suffix = 1,
|
||||
Extension = 2,
|
||||
SuffixAndExtension = 3,
|
||||
};
|
||||
inline SkipFile operator&(SkipFile a, SkipFile b) {
|
||||
return static_cast<SkipFile>(static_cast<int>(a) & static_cast<int>(b));
|
||||
}
|
||||
// Options for Namer::Directories
|
||||
enum class SkipDir {
|
||||
None = 0,
|
||||
// Skip prefixing the -o $output_path.
|
||||
OutputPath = 1,
|
||||
// Skip trailing path seperator.
|
||||
TrailingPathSeperator = 2,
|
||||
OutputPathAndTrailingPathSeparator = 3,
|
||||
};
|
||||
inline SkipDir operator&(SkipDir a, SkipDir b) {
|
||||
return static_cast<SkipDir>(static_cast<int>(a) & static_cast<int>(b));
|
||||
}
|
||||
|
||||
// `Namer` applies style configuration to symbols in generated code. It manages
|
||||
// casing, escapes keywords, and object API naming.
|
||||
// TODO: Refactor all code generators to use this.
|
||||
class Namer {
|
||||
public:
|
||||
struct Config {
|
||||
// Symbols in code.
|
||||
|
||||
// Case style for flatbuffers-defined types.
|
||||
// e.g. `class TableA {}`
|
||||
Case types;
|
||||
// Case style for flatbuffers-defined constants.
|
||||
// e.g. `uint64_t ENUM_A_MAX`;
|
||||
Case constants;
|
||||
// Case style for flatbuffers-defined methods.
|
||||
// e.g. `class TableA { int field_a(); }`
|
||||
Case methods;
|
||||
// Case style for flatbuffers-defined functions.
|
||||
// e.g. `TableA* get_table_a_root()`;
|
||||
Case functions;
|
||||
// Case style for flatbuffers-defined fields.
|
||||
// e.g. `struct Struct { int my_field; }`
|
||||
Case fields;
|
||||
// Case style for flatbuffers-defined variables.
|
||||
// e.g. `int my_variable = 2`
|
||||
Case variables;
|
||||
// Case style for flatbuffers-defined variants.
|
||||
// e.g. `enum class Enum { MyVariant, }`
|
||||
Case variants;
|
||||
// Seperator for qualified enum names.
|
||||
// e.g. `Enum::MyVariant` uses `::`.
|
||||
std::string enum_variant_seperator;
|
||||
|
||||
// Configures, when formatting code, whether symbols are checked against
|
||||
// keywords and escaped before or after case conversion. It does not make
|
||||
// sense to do so before, but its legacy behavior. :shrug:
|
||||
// TODO(caspern): Deprecate.
|
||||
enum class Escape {
|
||||
BeforeConvertingCase,
|
||||
AfterConvertingCase,
|
||||
};
|
||||
Escape escape_keywords;
|
||||
|
||||
// Namespaces
|
||||
|
||||
// e.g. `namespace my_namespace {}`
|
||||
Case namespaces;
|
||||
// The seperator between namespaces in a namespace path.
|
||||
std::string namespace_seperator;
|
||||
|
||||
// Object API.
|
||||
// Native versions flatbuffers types have this prefix.
|
||||
// e.g. "" (it's usually empty string)
|
||||
std::string object_prefix;
|
||||
// Native versions flatbuffers types have this suffix.
|
||||
// e.g. "T"
|
||||
std::string object_suffix;
|
||||
|
||||
// Keywords.
|
||||
// Prefix used to escape keywords. It is usually empty string.
|
||||
std::string keyword_prefix;
|
||||
// Suffix used to escape keywords. It is usually "_".
|
||||
std::string keyword_suffix;
|
||||
|
||||
// Files.
|
||||
|
||||
// Case style for filenames. e.g. `foo_bar_generated.rs`
|
||||
Case filenames;
|
||||
// Case style for directories, e.g. `output_files/foo_bar/baz/`
|
||||
Case directories;
|
||||
// The directory within which we will generate files.
|
||||
std::string output_path;
|
||||
// Suffix for generated file names, e.g. "_generated".
|
||||
std::string filename_suffix;
|
||||
// Extension for generated files, e.g. ".cpp" or ".rs".
|
||||
std::string filename_extension;
|
||||
};
|
||||
Namer(Config config, std::set<std::string> keywords)
|
||||
: config_(config), keywords_(std::move(keywords)) {}
|
||||
|
||||
virtual ~Namer() {}
|
||||
|
||||
template<typename T> std::string Method(const T &s) const {
|
||||
return Method(s.name);
|
||||
}
|
||||
|
||||
virtual std::string Method(const std::string &pre,
|
||||
const std::string &mid,
|
||||
const std::string &suf) const {
|
||||
return Format(pre + "_" + mid + "_" + suf, config_.methods);
|
||||
}
|
||||
virtual std::string Method(const std::string &pre,
|
||||
const std::string &suf) const {
|
||||
return Format(pre + "_" + suf, config_.methods);
|
||||
}
|
||||
virtual std::string Method(const std::string &s) const {
|
||||
return Format(s, config_.methods);
|
||||
}
|
||||
|
||||
virtual std::string Constant(const std::string &s) const {
|
||||
return Format(s, config_.constants);
|
||||
}
|
||||
|
||||
virtual std::string Function(const std::string &s) const {
|
||||
return Format(s, config_.functions);
|
||||
}
|
||||
|
||||
virtual std::string Variable(const std::string &s) const {
|
||||
return Format(s, config_.variables);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::string Variable(const std::string &p, const T &s) const {
|
||||
return Format(p + "_" + s.name, config_.variables);
|
||||
}
|
||||
virtual std::string Variable(const std::string &p,
|
||||
const std::string &s) const {
|
||||
return Format(p + "_" + s, config_.variables);
|
||||
}
|
||||
|
||||
virtual std::string Namespace(const std::string &s) const {
|
||||
return Format(s, config_.namespaces);
|
||||
}
|
||||
|
||||
virtual std::string Namespace(const std::vector<std::string> &ns) const {
|
||||
std::string result;
|
||||
for (auto it = ns.begin(); it != ns.end(); it++) {
|
||||
if (it != ns.begin()) result += config_.namespace_seperator;
|
||||
result += Namespace(*it);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual std::string NamespacedType(const std::vector<std::string> &ns,
|
||||
const std::string &s) const {
|
||||
return (ns.empty() ? "" : (Namespace(ns) + config_.namespace_seperator)) +
|
||||
Type(s);
|
||||
}
|
||||
|
||||
// Returns `filename` with the right casing, suffix, and extension.
|
||||
virtual std::string File(const std::string &filename,
|
||||
SkipFile skips = SkipFile::None) const {
|
||||
const bool skip_suffix = (skips & SkipFile::Suffix) != SkipFile::None;
|
||||
const bool skip_ext = (skips & SkipFile::Extension) != SkipFile::None;
|
||||
return ConvertCase(filename, config_.filenames, Case::kUpperCamel) +
|
||||
(skip_suffix ? "" : config_.filename_suffix) +
|
||||
(skip_ext ? "" : config_.filename_extension);
|
||||
}
|
||||
template<typename T>
|
||||
std::string File(const T &f, SkipFile skips = SkipFile::None) const {
|
||||
return File(f.name, skips);
|
||||
}
|
||||
|
||||
// Formats `directories` prefixed with the output_path and joined with the
|
||||
// right seperator. Output path prefixing and the trailing separator may be
|
||||
// skiped using `skips`.
|
||||
// Callers may want to use `EnsureDirExists` with the result.
|
||||
// input_case is used to tell how to modify namespace. e.g. kUpperCamel will
|
||||
// add a underscode between case changes, so MyGame turns into My_Game
|
||||
// (depending also on the output_case).
|
||||
virtual std::string Directories(const std::vector<std::string> &directories,
|
||||
SkipDir skips = SkipDir::None,
|
||||
Case input_case = Case::kUpperCamel) const {
|
||||
const bool skip_output_path =
|
||||
(skips & SkipDir::OutputPath) != SkipDir::None;
|
||||
const bool skip_trailing_seperator =
|
||||
(skips & SkipDir::TrailingPathSeperator) != SkipDir::None;
|
||||
std::string result = skip_output_path ? "" : config_.output_path;
|
||||
for (auto d = directories.begin(); d != directories.end(); d++) {
|
||||
result += ConvertCase(*d, config_.directories, input_case);
|
||||
result.push_back(kPathSeparator);
|
||||
}
|
||||
if (skip_trailing_seperator && !result.empty()) result.pop_back();
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual std::string EscapeKeyword(const std::string &name) const {
|
||||
if (keywords_.find(name) == keywords_.end()) {
|
||||
return name;
|
||||
} else {
|
||||
return config_.keyword_prefix + name + config_.keyword_suffix;
|
||||
}
|
||||
}
|
||||
|
||||
virtual std::string Type(const std::string &s) const {
|
||||
return Format(s, config_.types);
|
||||
}
|
||||
virtual std::string Type(const std::string &t, const std::string &s) const {
|
||||
return Format(t + "_" + s, config_.types);
|
||||
}
|
||||
|
||||
virtual std::string ObjectType(const std::string &s) const {
|
||||
return config_.object_prefix + Type(s) + config_.object_suffix;
|
||||
}
|
||||
|
||||
virtual std::string Field(const std::string &s) const {
|
||||
return Format(s, config_.fields);
|
||||
}
|
||||
|
||||
virtual std::string Variant(const std::string &s) const {
|
||||
return Format(s, config_.variants);
|
||||
}
|
||||
|
||||
virtual std::string Format(const std::string &s, Case casing) const {
|
||||
if (config_.escape_keywords == Config::Escape::BeforeConvertingCase) {
|
||||
return ConvertCase(EscapeKeyword(s), casing, Case::kLowerCamel);
|
||||
} else {
|
||||
return EscapeKeyword(ConvertCase(s, casing, Case::kLowerCamel));
|
||||
}
|
||||
}
|
||||
|
||||
// Denamespaces a string (e.g. The.Quick.Brown.Fox) by returning the last part
|
||||
// after the `delimiter` (Fox) and placing the rest in `namespace_prefix`
|
||||
// (The.Quick.Brown).
|
||||
virtual std::string Denamespace(const std::string &s,
|
||||
std::string &namespace_prefix,
|
||||
const char delimiter = '.') const {
|
||||
const size_t pos = s.find_last_of(delimiter);
|
||||
if (pos == std::string::npos) {
|
||||
namespace_prefix = "";
|
||||
return s;
|
||||
}
|
||||
namespace_prefix = s.substr(0, pos);
|
||||
return s.substr(pos + 1);
|
||||
}
|
||||
|
||||
// Same as above, but disregards the prefix.
|
||||
virtual std::string Denamespace(const std::string &s,
|
||||
const char delimiter = '.') const {
|
||||
std::string prefix;
|
||||
return Denamespace(s, prefix, delimiter);
|
||||
}
|
||||
|
||||
const Config config_;
|
||||
const std::set<std::string> keywords_;
|
||||
};
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // FLATBUFFERS_INCLUDE_CODEGEN_NAMER_H_
|
||||
63
include/codegen/python.cc
Normal file
63
include/codegen/python.cc
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "codegen/python.h"
|
||||
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace flatbuffers {
|
||||
namespace python {
|
||||
Version::Version(const std::string &version) {
|
||||
std::stringstream ss(version);
|
||||
char dot;
|
||||
ss >> major >> dot >> minor >> dot >> micro;
|
||||
}
|
||||
|
||||
bool Version::IsValid() const {
|
||||
return (major == 0 || major == 2 || major == 3) && minor >= 0 && micro >= 0;
|
||||
}
|
||||
|
||||
std::set<std::string> Keywords(const Version &version) {
|
||||
switch (version.major) {
|
||||
case 2:
|
||||
// https://docs.python.org/2/reference/lexical_analysis.html#keywords
|
||||
return {
|
||||
"and", "as", "assert", "break", "class", "continue", "def",
|
||||
"del", "elif", "else", "except", "exec", "finally", "for",
|
||||
"from", "global", "if", "import", "in", "is", "lambda",
|
||||
"not", "or", "pass", "print", "raise", "return", "try",
|
||||
"while", "with", "yield",
|
||||
};
|
||||
case 0:
|
||||
case 3:
|
||||
// https://docs.python.org/3/reference/lexical_analysis.html#keywords
|
||||
return {
|
||||
"and", "as", "assert", "async", "await", "break",
|
||||
"class", "continue", "def", "del", "elif", "else",
|
||||
"except", "False", "finally", "for", "from", "global",
|
||||
"if", "import", "in", "is", "lambda", "None",
|
||||
"nonlocal", "not", "or", "pass", "raise", "return",
|
||||
"True", "try", "while", "with", "yield",
|
||||
};
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
const python::Import &python::Imports::Import(const std::string &module) {
|
||||
python::Import import;
|
||||
import.module = module;
|
||||
imports.push_back(std::move(import));
|
||||
return imports.back();
|
||||
}
|
||||
|
||||
const python::Import &python::Imports::Import(const std::string &module,
|
||||
const std::string &name) {
|
||||
python::Import import;
|
||||
import.module = module;
|
||||
import.name = name;
|
||||
imports.push_back(std::move(import));
|
||||
return imports.back();
|
||||
}
|
||||
} // namespace python
|
||||
} // namespace flatbuffers
|
||||
93
include/codegen/python.h
Normal file
93
include/codegen/python.h
Normal file
@@ -0,0 +1,93 @@
|
||||
#ifndef FLATBUFFERS_INCLUDE_CODEGEN_PYTHON_H_
|
||||
#define FLATBUFFERS_INCLUDE_CODEGEN_PYTHON_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "codegen/namer.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
namespace python {
|
||||
static const Namer::Config kConfig = {
|
||||
/*types=*/Case::kKeep,
|
||||
/*constants=*/Case::kScreamingSnake,
|
||||
/*methods=*/Case::kUpperCamel,
|
||||
/*functions=*/Case::kUpperCamel,
|
||||
/*fields=*/Case::kLowerCamel,
|
||||
/*variable=*/Case::kLowerCamel,
|
||||
/*variants=*/Case::kKeep,
|
||||
/*enum_variant_seperator=*/".",
|
||||
/*escape_keywords=*/Namer::Config::Escape::AfterConvertingCase,
|
||||
/*namespaces=*/Case::kKeep, // Packages in python.
|
||||
/*namespace_seperator=*/".",
|
||||
/*object_prefix=*/"",
|
||||
/*object_suffix=*/"T",
|
||||
/*keyword_prefix=*/"",
|
||||
/*keyword_suffix=*/"_",
|
||||
/*filenames=*/Case::kKeep,
|
||||
/*directories=*/Case::kKeep,
|
||||
/*output_path=*/"",
|
||||
/*filename_suffix=*/"",
|
||||
/*filename_extension=*/".py",
|
||||
};
|
||||
|
||||
static const Namer::Config kStubConfig = {
|
||||
/*types=*/Case::kKeep,
|
||||
/*constants=*/Case::kScreamingSnake,
|
||||
/*methods=*/Case::kUpperCamel,
|
||||
/*functions=*/Case::kUpperCamel,
|
||||
/*fields=*/Case::kLowerCamel,
|
||||
/*variables=*/Case::kLowerCamel,
|
||||
/*variants=*/Case::kKeep,
|
||||
/*enum_variant_seperator=*/".",
|
||||
/*escape_keywords=*/Namer::Config::Escape::AfterConvertingCase,
|
||||
/*namespaces=*/Case::kKeep, // Packages in python.
|
||||
/*namespace_seperator=*/".",
|
||||
/*object_prefix=*/"",
|
||||
/*object_suffix=*/"T",
|
||||
/*keyword_prefix=*/"",
|
||||
/*keyword_suffix=*/"_",
|
||||
/*filenames=*/Case::kKeep,
|
||||
/*directories=*/Case::kKeep,
|
||||
/*output_path=*/"",
|
||||
/*filename_suffix=*/"",
|
||||
/*filename_extension=*/".pyi",
|
||||
};
|
||||
|
||||
// `Version` represent a Python version.
|
||||
//
|
||||
// The zero value (i.e. `Version{}`) represents both Python2 and Python3.
|
||||
//
|
||||
// https://docs.python.org/3/faq/general.html#how-does-the-python-version-numbering-scheme-work
|
||||
struct Version {
|
||||
explicit Version(const std::string &version);
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
int16_t major = 0;
|
||||
int16_t minor = 0;
|
||||
int16_t micro = 0;
|
||||
};
|
||||
|
||||
std::set<std::string> Keywords(const Version &version);
|
||||
|
||||
struct Import {
|
||||
bool IsLocal() const { return module == "."; }
|
||||
|
||||
std::string module;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
struct Imports {
|
||||
const python::Import &Import(const std::string &module);
|
||||
const python::Import &Import(const std::string &module,
|
||||
const std::string &name);
|
||||
|
||||
std::vector<python::Import> imports;
|
||||
};
|
||||
} // namespace python
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // FLATBUFFERS_INCLUDE_CODEGEN_PYTHON_H_
|
||||
@@ -140,8 +140,8 @@
|
||||
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
|
||||
|
||||
#define FLATBUFFERS_VERSION_MAJOR 24
|
||||
#define FLATBUFFERS_VERSION_MINOR 3
|
||||
#define FLATBUFFERS_VERSION_REVISION 7
|
||||
#define FLATBUFFERS_VERSION_MINOR 12
|
||||
#define FLATBUFFERS_VERSION_REVISION 23
|
||||
#define FLATBUFFERS_STRING_EXPAND(X) #X
|
||||
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
|
||||
namespace flatbuffers {
|
||||
@@ -339,15 +339,15 @@ typedef uint16_t voffset_t;
|
||||
typedef uintmax_t largest_scalar_t;
|
||||
|
||||
// In 32bits, this evaluates to 2GB - 1
|
||||
#define FLATBUFFERS_MAX_BUFFER_SIZE std::numeric_limits<::flatbuffers::soffset_t>::max()
|
||||
#define FLATBUFFERS_MAX_64_BUFFER_SIZE std::numeric_limits<::flatbuffers::soffset64_t>::max()
|
||||
#define FLATBUFFERS_MAX_BUFFER_SIZE (std::numeric_limits<::flatbuffers::soffset_t>::max)()
|
||||
#define FLATBUFFERS_MAX_64_BUFFER_SIZE (std::numeric_limits<::flatbuffers::soffset64_t>::max)()
|
||||
|
||||
// The minimum size buffer that can be a valid flatbuffer.
|
||||
// Includes the offset to the root table (uoffset_t), the offset to the vtable
|
||||
// of the root table (soffset_t), the size of the vtable (uint16_t), and the
|
||||
// size of the referring table (uint16_t).
|
||||
#define FLATBUFFERS_MIN_BUFFER_SIZE sizeof(uoffset_t) + sizeof(soffset_t) + \
|
||||
sizeof(uint16_t) + sizeof(uint16_t)
|
||||
#define FLATBUFFERS_MIN_BUFFER_SIZE sizeof(::flatbuffers::uoffset_t) + \
|
||||
sizeof(::flatbuffers::soffset_t) + sizeof(uint16_t) + sizeof(uint16_t)
|
||||
|
||||
// We support aligning the contents of buffers up to this size.
|
||||
#ifndef FLATBUFFERS_MAX_ALIGNMENT
|
||||
@@ -459,10 +459,17 @@ inline size_t PaddingBytes(size_t buf_size, size_t scalar_size) {
|
||||
return ((~buf_size) + 1) & (scalar_size - 1);
|
||||
}
|
||||
|
||||
#if !defined(_MSC_VER)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wfloat-equal"
|
||||
#endif
|
||||
// Generic 'operator==' with conditional specialisations.
|
||||
// T e - new value of a scalar field.
|
||||
// T def - default of scalar (is known at compile-time).
|
||||
template<typename T> inline bool IsTheSameAs(T e, T def) { return e == def; }
|
||||
#if !defined(_MSC_VER)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#if defined(FLATBUFFERS_NAN_DEFAULTS) && \
|
||||
defined(FLATBUFFERS_HAS_NEW_STRTOD) && (FLATBUFFERS_HAS_NEW_STRTOD > 0)
|
||||
|
||||
@@ -80,6 +80,11 @@ class DetachedBuffer {
|
||||
|
||||
size_t size() const { return size_; }
|
||||
|
||||
uint8_t *begin() { return data(); }
|
||||
const uint8_t *begin() const { return data(); }
|
||||
uint8_t *end() { return data() + size(); }
|
||||
const uint8_t *end() const { return data() + size(); }
|
||||
|
||||
// These may change access mode, leave these at end of public section
|
||||
FLATBUFFERS_DELETE_FUNC(DetachedBuffer(const DetachedBuffer &other));
|
||||
FLATBUFFERS_DELETE_FUNC(
|
||||
|
||||
@@ -47,7 +47,8 @@ inline voffset_t FieldIndexToOffset(voffset_t field_id) {
|
||||
2 * sizeof(voffset_t); // Vtable size and Object Size.
|
||||
size_t offset = fixed_fields + field_id * sizeof(voffset_t);
|
||||
FLATBUFFERS_ASSERT(offset < std::numeric_limits<voffset_t>::max());
|
||||
return static_cast<voffset_t>(offset);}
|
||||
return static_cast<voffset_t>(offset);
|
||||
}
|
||||
|
||||
template<typename T, typename Alloc = std::allocator<T>>
|
||||
const T *data(const std::vector<T, Alloc> &v) {
|
||||
@@ -241,7 +242,7 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
|
||||
/// called.
|
||||
uint8_t *ReleaseRaw(size_t &size, size_t &offset) {
|
||||
Finished();
|
||||
uint8_t* raw = buf_.release_raw(size, offset);
|
||||
uint8_t *raw = buf_.release_raw(size, offset);
|
||||
Clear();
|
||||
return raw;
|
||||
}
|
||||
@@ -561,7 +562,7 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
|
||||
return CreateString<OffsetT>(str.c_str(), str.length());
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
// clang-format off
|
||||
#ifdef FLATBUFFERS_HAS_STRING_VIEW
|
||||
/// @brief Store a string in the buffer, which can contain any binary data.
|
||||
/// @param[in] str A const string_view to copy in to the buffer.
|
||||
@@ -743,7 +744,7 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
|
||||
AssertScalarT<T>();
|
||||
StartVector<T, OffsetT, LenT>(len);
|
||||
if (len > 0) {
|
||||
// clang-format off
|
||||
// clang-format off
|
||||
#if FLATBUFFERS_LITTLEENDIAN
|
||||
PushBytes(reinterpret_cast<const uint8_t *>(v), len * sizeof(T));
|
||||
#else
|
||||
@@ -1470,7 +1471,8 @@ T *GetMutableTemporaryPointer(FlatBufferBuilder &fbb, Offset<T> offset) {
|
||||
|
||||
template<typename T>
|
||||
const T *GetTemporaryPointer(const FlatBufferBuilder &fbb, Offset<T> offset) {
|
||||
return GetMutableTemporaryPointer<T>(fbb, offset);
|
||||
return reinterpret_cast<const T *>(fbb.GetCurrentBufferPointer() +
|
||||
fbb.GetSize() - offset.o);
|
||||
}
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
@@ -367,7 +367,8 @@ inline void IndentString(std::string &s, int indent,
|
||||
|
||||
template<typename T>
|
||||
void AppendToString(std::string &s, T &&v, bool keys_quoted, bool indented,
|
||||
int cur_indent, const char *indent_string) {
|
||||
int cur_indent, const char *indent_string,
|
||||
bool natural_utf8) {
|
||||
s += "[";
|
||||
s += indented ? "\n" : " ";
|
||||
for (size_t i = 0; i < v.size(); i++) {
|
||||
@@ -377,7 +378,7 @@ void AppendToString(std::string &s, T &&v, bool keys_quoted, bool indented,
|
||||
}
|
||||
if (indented) IndentString(s, cur_indent, indent_string);
|
||||
v[i].ToString(true, keys_quoted, s, indented, cur_indent,
|
||||
indent_string);
|
||||
indent_string, natural_utf8);
|
||||
}
|
||||
if (indented) {
|
||||
s += "\n";
|
||||
@@ -567,23 +568,24 @@ class Reference {
|
||||
// string values at the top level receive "" quotes (inside other values
|
||||
// they always do). keys_quoted determines if keys are quoted, at any level.
|
||||
void ToString(bool strings_quoted, bool keys_quoted, std::string &s) const {
|
||||
ToString(strings_quoted, keys_quoted, s, false, 0, "");
|
||||
ToString(strings_quoted, keys_quoted, s, false, 0, "", false);
|
||||
}
|
||||
|
||||
// This version additionally allow you to specify if you want indentation.
|
||||
void ToString(bool strings_quoted, bool keys_quoted, std::string &s,
|
||||
bool indented, int cur_indent, const char *indent_string) const {
|
||||
bool indented, int cur_indent, const char *indent_string,
|
||||
bool natural_utf8 = false) const {
|
||||
if (type_ == FBT_STRING) {
|
||||
String str(Indirect(), byte_width_);
|
||||
if (strings_quoted) {
|
||||
flatbuffers::EscapeString(str.c_str(), str.length(), &s, true, false);
|
||||
flatbuffers::EscapeString(str.c_str(), str.length(), &s, true, natural_utf8);
|
||||
} else {
|
||||
s.append(str.c_str(), str.length());
|
||||
}
|
||||
} else if (IsKey()) {
|
||||
auto str = AsKey();
|
||||
if (keys_quoted) {
|
||||
flatbuffers::EscapeString(str, strlen(str), &s, true, false);
|
||||
flatbuffers::EscapeString(str, strlen(str), &s, true, natural_utf8);
|
||||
} else {
|
||||
s += str;
|
||||
}
|
||||
@@ -623,7 +625,8 @@ class Reference {
|
||||
if (indented) IndentString(s, cur_indent + 1, indent_string);
|
||||
keys[i].ToString(true, kq, s);
|
||||
s += ": ";
|
||||
vals[i].ToString(true, keys_quoted, s, indented, cur_indent + 1, indent_string);
|
||||
vals[i].ToString(true, keys_quoted, s, indented, cur_indent + 1, indent_string,
|
||||
natural_utf8);
|
||||
if (i < keys.size() - 1) {
|
||||
s += ",";
|
||||
if (!indented) s += " ";
|
||||
@@ -635,13 +638,15 @@ class Reference {
|
||||
s += "}";
|
||||
} else if (IsVector()) {
|
||||
AppendToString<Vector>(s, AsVector(), keys_quoted, indented,
|
||||
cur_indent + 1, indent_string);
|
||||
cur_indent + 1, indent_string, natural_utf8);
|
||||
} else if (IsTypedVector()) {
|
||||
AppendToString<TypedVector>(s, AsTypedVector(), keys_quoted, indented,
|
||||
cur_indent + 1, indent_string);
|
||||
cur_indent + 1, indent_string,
|
||||
natural_utf8);
|
||||
} else if (IsFixedTypedVector()) {
|
||||
AppendToString<FixedTypedVector>(s, AsFixedTypedVector(), keys_quoted,
|
||||
indented, cur_indent + 1, indent_string);
|
||||
indented, cur_indent + 1, indent_string,
|
||||
natural_utf8);
|
||||
} else if (IsBlob()) {
|
||||
auto blob = AsBlob();
|
||||
flatbuffers::EscapeString(reinterpret_cast<const char *>(blob.data()),
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
|
||||
#include "flatbuffers/base.h"
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
@@ -705,8 +706,26 @@ struct IDLOptions {
|
||||
bool no_leak_private_annotations;
|
||||
bool require_json_eof;
|
||||
bool keep_proto_id;
|
||||
|
||||
/********************************** Python **********************************/
|
||||
bool python_no_type_prefix_suffix;
|
||||
bool python_typing;
|
||||
|
||||
// The target Python version. Can be one of the following:
|
||||
// - "0"
|
||||
// - "2"
|
||||
// - "3"
|
||||
// - "2.<minor>"
|
||||
// - "3.<minor>"
|
||||
// - "2.<minor>.<micro>"
|
||||
// - "3.<minor>.<micro>"
|
||||
//
|
||||
// https://docs.python.org/3/faq/general.html#how-does-the-python-version-numbering-scheme-work
|
||||
std::string python_version;
|
||||
|
||||
// Whether to generate numpy helpers.
|
||||
bool python_gen_numpy;
|
||||
|
||||
bool ts_omit_entrypoint;
|
||||
ProtoIdGapAction proto_id_gap_action;
|
||||
|
||||
@@ -759,6 +778,15 @@ struct IDLOptions {
|
||||
// make the flatbuffer more compact.
|
||||
bool set_empty_vectors_to_null;
|
||||
|
||||
/*********************************** gRPC ***********************************/
|
||||
std::string grpc_filename_suffix;
|
||||
bool grpc_use_system_headers;
|
||||
std::string grpc_search_path;
|
||||
std::vector<std::string> grpc_additional_headers;
|
||||
|
||||
/******************************* Python gRPC ********************************/
|
||||
bool grpc_python_typed_handlers;
|
||||
|
||||
IDLOptions()
|
||||
: gen_jvmstatic(false),
|
||||
use_flexbuffers(false),
|
||||
@@ -821,6 +849,7 @@ struct IDLOptions {
|
||||
keep_proto_id(false),
|
||||
python_no_type_prefix_suffix(false),
|
||||
python_typing(false),
|
||||
python_gen_numpy(true),
|
||||
ts_omit_entrypoint(false),
|
||||
proto_id_gap_action(ProtoIdGapAction::WARNING),
|
||||
mini_reflect(IDLOptions::kNone),
|
||||
@@ -829,7 +858,10 @@ struct IDLOptions {
|
||||
rust_module_root_file(false),
|
||||
lang_to_generate(0),
|
||||
set_empty_strings_to_null(true),
|
||||
set_empty_vectors_to_null(true) {}
|
||||
set_empty_vectors_to_null(true),
|
||||
grpc_filename_suffix(".fb"),
|
||||
grpc_use_system_headers(true),
|
||||
grpc_python_typed_handlers(false) {}
|
||||
};
|
||||
|
||||
// This encapsulates where the parser is in the current source file.
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 24 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 3 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 7,
|
||||
FLATBUFFERS_VERSION_MINOR == 12 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 23,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace reflection {
|
||||
@@ -274,6 +274,12 @@ struct KeyValue FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
int KeyCompareWithValue(const char *_key) const {
|
||||
return strcmp(key()->c_str(), _key);
|
||||
}
|
||||
template<typename StringType>
|
||||
int KeyCompareWithValue(const StringType& _key) const {
|
||||
if (key()->c_str() < _key) return -1;
|
||||
if (_key < key()->c_str()) return 1;
|
||||
return 0;
|
||||
}
|
||||
const ::flatbuffers::String *value() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_VALUE);
|
||||
}
|
||||
@@ -464,6 +470,12 @@ struct Enum FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
int KeyCompareWithValue(const char *_name) const {
|
||||
return strcmp(name()->c_str(), _name);
|
||||
}
|
||||
template<typename StringType>
|
||||
int KeyCompareWithValue(const StringType& _name) const {
|
||||
if (name()->c_str() < _name) return -1;
|
||||
if (_name < name()->c_str()) return 1;
|
||||
return 0;
|
||||
}
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<reflection::EnumVal>> *values() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<reflection::EnumVal>> *>(VT_VALUES);
|
||||
}
|
||||
@@ -616,6 +628,12 @@ struct Field FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
int KeyCompareWithValue(const char *_name) const {
|
||||
return strcmp(name()->c_str(), _name);
|
||||
}
|
||||
template<typename StringType>
|
||||
int KeyCompareWithValue(const StringType& _name) const {
|
||||
if (name()->c_str() < _name) return -1;
|
||||
if (_name < name()->c_str()) return 1;
|
||||
return 0;
|
||||
}
|
||||
const reflection::Type *type() const {
|
||||
return GetPointer<const reflection::Type *>(VT_TYPE);
|
||||
}
|
||||
@@ -834,6 +852,12 @@ struct Object FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
int KeyCompareWithValue(const char *_name) const {
|
||||
return strcmp(name()->c_str(), _name);
|
||||
}
|
||||
template<typename StringType>
|
||||
int KeyCompareWithValue(const StringType& _name) const {
|
||||
if (name()->c_str() < _name) return -1;
|
||||
if (_name < name()->c_str()) return 1;
|
||||
return 0;
|
||||
}
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<reflection::Field>> *fields() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<reflection::Field>> *>(VT_FIELDS);
|
||||
}
|
||||
@@ -986,6 +1010,12 @@ struct RPCCall FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
int KeyCompareWithValue(const char *_name) const {
|
||||
return strcmp(name()->c_str(), _name);
|
||||
}
|
||||
template<typename StringType>
|
||||
int KeyCompareWithValue(const StringType& _name) const {
|
||||
if (name()->c_str() < _name) return -1;
|
||||
if (_name < name()->c_str()) return 1;
|
||||
return 0;
|
||||
}
|
||||
const reflection::Object *request() const {
|
||||
return GetPointer<const reflection::Object *>(VT_REQUEST);
|
||||
}
|
||||
@@ -1102,6 +1132,12 @@ struct Service FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
int KeyCompareWithValue(const char *_name) const {
|
||||
return strcmp(name()->c_str(), _name);
|
||||
}
|
||||
template<typename StringType>
|
||||
int KeyCompareWithValue(const StringType& _name) const {
|
||||
if (name()->c_str() < _name) return -1;
|
||||
if (_name < name()->c_str()) return 1;
|
||||
return 0;
|
||||
}
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<reflection::RPCCall>> *calls() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<reflection::RPCCall>> *>(VT_CALLS);
|
||||
}
|
||||
@@ -1221,6 +1257,12 @@ struct SchemaFile FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
int KeyCompareWithValue(const char *_filename) const {
|
||||
return strcmp(filename()->c_str(), _filename);
|
||||
}
|
||||
template<typename StringType>
|
||||
int KeyCompareWithValue(const StringType& _filename) const {
|
||||
if (filename()->c_str() < _filename) return -1;
|
||||
if (_filename < filename()->c_str()) return 1;
|
||||
return 0;
|
||||
}
|
||||
/// Names of included files, relative to project root.
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>> *included_filenames() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>> *>(VT_INCLUDED_FILENAMES);
|
||||
|
||||
@@ -273,7 +273,7 @@ template<class T, class U>
|
||||
FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(const Optional<T>& lhs, const Optional<U>& rhs) FLATBUFFERS_NOEXCEPT {
|
||||
return static_cast<bool>(lhs) != static_cast<bool>(rhs)
|
||||
? false
|
||||
: !static_cast<bool>(lhs) ? false : (*lhs == *rhs);
|
||||
: !static_cast<bool>(lhs) ? true : (*lhs == *rhs);
|
||||
}
|
||||
#endif // FLATBUFFERS_USE_STD_OPTIONAL
|
||||
|
||||
|
||||
@@ -56,12 +56,24 @@ struct VectorIterator {
|
||||
return data_ == other.data_;
|
||||
}
|
||||
|
||||
bool operator!=(const VectorIterator &other) const {
|
||||
return data_ != other.data_;
|
||||
}
|
||||
|
||||
bool operator<(const VectorIterator &other) const {
|
||||
return data_ < other.data_;
|
||||
}
|
||||
|
||||
bool operator!=(const VectorIterator &other) const {
|
||||
return data_ != other.data_;
|
||||
bool operator>(const VectorIterator &other) const {
|
||||
return data_ > other.data_;
|
||||
}
|
||||
|
||||
bool operator<=(const VectorIterator &other) const {
|
||||
return !(data_ > other.data_);
|
||||
}
|
||||
|
||||
bool operator>=(const VectorIterator &other) const {
|
||||
return !(data_ < other.data_);
|
||||
}
|
||||
|
||||
difference_type operator-(const VectorIterator &other) const {
|
||||
@@ -163,6 +175,11 @@ template<typename T, typename SizeT = uoffset_t> class Vector {
|
||||
|
||||
SizeT size() const { return EndianScalar(length_); }
|
||||
|
||||
// Returns true if the vector is empty.
|
||||
//
|
||||
// This just provides another standardized method that is expected of vectors.
|
||||
bool empty() const { return size() == 0; }
|
||||
|
||||
// Deprecated: use size(). Here for backwards compatibility.
|
||||
FLATBUFFERS_ATTRIBUTE([[deprecated("use size() instead")]])
|
||||
SizeT Length() const { return size(); }
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
namespace flatbuffers {
|
||||
|
||||
// Helper class to verify the integrity of a FlatBuffer
|
||||
class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
template <bool TrackVerifierBufferSize>
|
||||
class VerifierTemplate FLATBUFFERS_FINAL_CLASS {
|
||||
public:
|
||||
struct Options {
|
||||
// The maximum nesting of tables and vectors before we call it invalid.
|
||||
@@ -40,17 +41,18 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
bool assert = false;
|
||||
};
|
||||
|
||||
explicit Verifier(const uint8_t *const buf, const size_t buf_len,
|
||||
const Options &opts)
|
||||
explicit VerifierTemplate(const uint8_t *const buf, const size_t buf_len,
|
||||
const Options &opts)
|
||||
: buf_(buf), size_(buf_len), opts_(opts) {
|
||||
FLATBUFFERS_ASSERT(size_ < opts.max_size);
|
||||
}
|
||||
|
||||
// Deprecated API, please construct with Verifier::Options.
|
||||
Verifier(const uint8_t *const buf, const size_t buf_len,
|
||||
const uoffset_t max_depth = 64, const uoffset_t max_tables = 1000000,
|
||||
const bool check_alignment = true)
|
||||
: Verifier(buf, buf_len, [&] {
|
||||
// Deprecated API, please construct with VerifierTemplate::Options.
|
||||
VerifierTemplate(const uint8_t *const buf, const size_t buf_len,
|
||||
const uoffset_t max_depth = 64,
|
||||
const uoffset_t max_tables = 1000000,
|
||||
const bool check_alignment = true)
|
||||
: VerifierTemplate(buf, buf_len, [&] {
|
||||
Options opts;
|
||||
opts.max_depth = max_depth;
|
||||
opts.max_tables = max_tables;
|
||||
@@ -62,25 +64,25 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
bool Check(const bool ok) const {
|
||||
// clang-format off
|
||||
#ifdef FLATBUFFERS_DEBUG_VERIFICATION_FAILURE
|
||||
if (opts_.assert) { FLATBUFFERS_ASSERT(ok); }
|
||||
#endif
|
||||
#ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
||||
if (!ok)
|
||||
upper_bound_ = 0;
|
||||
if (opts_.assert) { FLATBUFFERS_ASSERT(ok); }
|
||||
#endif
|
||||
// clang-format on
|
||||
if (TrackVerifierBufferSize) {
|
||||
if (!ok) {
|
||||
upper_bound_ = 0;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
// Verify any range within the buffer.
|
||||
bool Verify(const size_t elem, const size_t elem_len) const {
|
||||
// clang-format off
|
||||
#ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
||||
if (TrackVerifierBufferSize) {
|
||||
auto upper_bound = elem + elem_len;
|
||||
if (upper_bound_ < upper_bound)
|
||||
if (upper_bound_ < upper_bound) {
|
||||
upper_bound_ = upper_bound;
|
||||
#endif
|
||||
// clang-format on
|
||||
}
|
||||
}
|
||||
return Check(elem_len < size_ && elem <= size_ - elem_len);
|
||||
}
|
||||
|
||||
@@ -210,14 +212,14 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
|
||||
// Call T::Verify, which must be in the generated code for this type.
|
||||
const auto o = VerifyOffset<uoffset_t>(start);
|
||||
return Check(o != 0) &&
|
||||
reinterpret_cast<const T *>(buf_ + start + o)->Verify(*this)
|
||||
// clang-format off
|
||||
#ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
||||
&& GetComputedSize()
|
||||
#endif
|
||||
;
|
||||
// clang-format on
|
||||
if (!Check(o != 0)) return false;
|
||||
if (!(reinterpret_cast<const T *>(buf_ + start + o)->Verify(*this))) {
|
||||
return false;
|
||||
}
|
||||
if (TrackVerifierBufferSize) {
|
||||
if (GetComputedSize() == 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T, int &..., typename SizeT>
|
||||
@@ -232,7 +234,8 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
// If there is a nested buffer, it must be greater than the min size.
|
||||
if (!Check(buf->size() >= FLATBUFFERS_MIN_BUFFER_SIZE)) return false;
|
||||
|
||||
Verifier nested_verifier(buf->data(), buf->size(), opts_);
|
||||
VerifierTemplate<TrackVerifierBufferSize> nested_verifier(
|
||||
buf->data(), buf->size(), opts_);
|
||||
return nested_verifier.VerifyBuffer<T>(identifier);
|
||||
}
|
||||
|
||||
@@ -286,21 +289,27 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns the message size in bytes
|
||||
// Returns the message size in bytes.
|
||||
//
|
||||
// This should only be called after first calling VerifyBuffer or
|
||||
// VerifySizePrefixedBuffer.
|
||||
//
|
||||
// This method should only be called for VerifierTemplate instances
|
||||
// where the TrackVerifierBufferSize template parameter is true,
|
||||
// i.e. for SizeVerifier. For instances where TrackVerifierBufferSize
|
||||
// is false, this fails at runtime or returns zero.
|
||||
size_t GetComputedSize() const {
|
||||
// clang-format off
|
||||
#ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
||||
if (TrackVerifierBufferSize) {
|
||||
uintptr_t size = upper_bound_;
|
||||
// Align the size to uoffset_t
|
||||
size = (size - 1 + sizeof(uoffset_t)) & ~(sizeof(uoffset_t) - 1);
|
||||
return (size > size_) ? 0 : size;
|
||||
#else
|
||||
// Must turn on FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE for this to work.
|
||||
(void)upper_bound_;
|
||||
FLATBUFFERS_ASSERT(false);
|
||||
return 0;
|
||||
#endif
|
||||
// clang-format on
|
||||
}
|
||||
// Must use SizeVerifier, or (deprecated) turn on
|
||||
// FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE, for this to work.
|
||||
(void)upper_bound_;
|
||||
FLATBUFFERS_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> *GetFlexReuseTracker() { return flex_reuse_tracker_; }
|
||||
@@ -323,9 +332,32 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
|
||||
// Specialization for 64-bit offsets.
|
||||
template<>
|
||||
inline size_t Verifier::VerifyOffset<uoffset64_t>(const size_t start) const {
|
||||
template<>
|
||||
inline size_t VerifierTemplate<false>::VerifyOffset<uoffset64_t>(
|
||||
const size_t start) const {
|
||||
return VerifyOffset<uoffset64_t, soffset64_t>(start);
|
||||
}
|
||||
template<>
|
||||
template<>
|
||||
inline size_t VerifierTemplate<true>::VerifyOffset<uoffset64_t>(
|
||||
const size_t start) const {
|
||||
return VerifyOffset<uoffset64_t, soffset64_t>(start);
|
||||
}
|
||||
|
||||
// Instance of VerifierTemplate that supports GetComputedSize().
|
||||
using SizeVerifier = VerifierTemplate</*TrackVerifierBufferSize = */ true>;
|
||||
|
||||
// The FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE build configuration macro is
|
||||
// deprecated, and should not be defined, since it is easy to misuse in ways
|
||||
// that result in ODR violations. Rather than using Verifier and defining
|
||||
// FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE, please use SizeVerifier instead.
|
||||
#ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE // Deprecated, see above.
|
||||
using Verifier = SizeVerifier;
|
||||
#else
|
||||
// Instance of VerifierTemplate that is slightly faster, but does not
|
||||
// support GetComputedSize().
|
||||
using Verifier = VerifierTemplate</*TrackVerifierBufferSize = */ false>;
|
||||
#endif
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.google.flatbuffers</groupId>
|
||||
<artifactId>flatbuffers-java</artifactId>
|
||||
<version>24.3.7</version>
|
||||
<version>24.12.23</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>FlatBuffers Java API</name>
|
||||
<description>
|
||||
|
||||
@@ -46,7 +46,7 @@ public class Constants {
|
||||
Changes to the Java implementation need to be sure to change
|
||||
the version here and in the code generator on every possible
|
||||
incompatible change */
|
||||
public static void FLATBUFFERS_24_3_7() {}
|
||||
public static void FLATBUFFERS_24_12_23() {}
|
||||
}
|
||||
|
||||
/// @endcond
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Enum extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_7(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_12_23(); }
|
||||
public static Enum getRootAsEnum(ByteBuffer _bb) { return getRootAsEnum(_bb, new Enum()); }
|
||||
public static Enum getRootAsEnum(ByteBuffer _bb, Enum 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); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class EnumVal extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_7(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_12_23(); }
|
||||
public static EnumVal getRootAsEnumVal(ByteBuffer _bb) { return getRootAsEnumVal(_bb, new EnumVal()); }
|
||||
public static EnumVal getRootAsEnumVal(ByteBuffer _bb, EnumVal 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); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Field extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_7(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_12_23(); }
|
||||
public static Field getRootAsField(ByteBuffer _bb) { return getRootAsField(_bb, new Field()); }
|
||||
public static Field getRootAsField(ByteBuffer _bb, Field 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); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class KeyValue extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_7(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_12_23(); }
|
||||
public static KeyValue getRootAsKeyValue(ByteBuffer _bb) { return getRootAsKeyValue(_bb, new KeyValue()); }
|
||||
public static KeyValue getRootAsKeyValue(ByteBuffer _bb, KeyValue 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); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Object extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_7(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_12_23(); }
|
||||
public static Object getRootAsObject(ByteBuffer _bb) { return getRootAsObject(_bb, new Object()); }
|
||||
public static Object getRootAsObject(ByteBuffer _bb, Object 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); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class RPCCall extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_7(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_12_23(); }
|
||||
public static RPCCall getRootAsRPCCall(ByteBuffer _bb) { return getRootAsRPCCall(_bb, new RPCCall()); }
|
||||
public static RPCCall getRootAsRPCCall(ByteBuffer _bb, RPCCall 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); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Schema extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_7(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_12_23(); }
|
||||
public static Schema getRootAsSchema(ByteBuffer _bb) { return getRootAsSchema(_bb, new Schema()); }
|
||||
public static Schema getRootAsSchema(ByteBuffer _bb, Schema obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public static boolean SchemaBufferHasIdentifier(ByteBuffer _bb) { return __has_identifier(_bb, "BFBS"); }
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.nio.ByteOrder;
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public final class SchemaFile extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_7(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_12_23(); }
|
||||
public static SchemaFile getRootAsSchemaFile(ByteBuffer _bb) { return getRootAsSchemaFile(_bb, new SchemaFile()); }
|
||||
public static SchemaFile getRootAsSchemaFile(ByteBuffer _bb, SchemaFile 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); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Service extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_7(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_12_23(); }
|
||||
public static Service getRootAsService(ByteBuffer _bb) { return getRootAsService(_bb, new Service()); }
|
||||
public static Service getRootAsService(ByteBuffer _bb, Service 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); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Type extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_7(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_12_23(); }
|
||||
public static Type getRootAsType(ByteBuffer _bb) { return getRootAsType(_bb, new Type()); }
|
||||
public static Type getRootAsType(ByteBuffer _bb, Type 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); }
|
||||
|
||||
7
kotlin/convention-plugins/build.gradle.kts
Normal file
7
kotlin/convention-plugins/build.gradle.kts
Normal file
@@ -0,0 +1,7 @@
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import org.gradle.api.publish.maven.MavenPublication
|
||||
import org.gradle.api.tasks.bundling.Jar
|
||||
import org.gradle.kotlin.dsl.`maven-publish`
|
||||
import org.gradle.kotlin.dsl.signing
|
||||
import java.util.*
|
||||
|
||||
plugins {
|
||||
`maven-publish`
|
||||
signing
|
||||
}
|
||||
|
||||
// Stub secrets to let the project sync and build without the publication values set up
|
||||
ext["signing.keyId"] = null
|
||||
ext["signing.password"] = null
|
||||
ext["signing.secretKeyRingFile"] = null
|
||||
ext["ossrhUsername"] = null
|
||||
ext["ossrhPassword"] = null
|
||||
|
||||
// Grabbing secrets from local.properties file or from environment variables, which could be used on CI
|
||||
val secretPropsFile = project.rootProject.file("local.properties")
|
||||
if (secretPropsFile.exists()) {
|
||||
secretPropsFile.reader().use {
|
||||
Properties().apply {
|
||||
load(it)
|
||||
}
|
||||
}.onEach { (name, value) ->
|
||||
ext[name.toString()] = value
|
||||
}
|
||||
} else {
|
||||
ext["signing.keyId"] = System.getenv("OSSRH_USERNAME")
|
||||
ext["signing.password"] = System.getenv("OSSRH_PASSWORD")
|
||||
ext["signing.secretKeyRingFile"] = System.getenv("INPUT_GPG_PRIVATE_KEY")
|
||||
ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME")
|
||||
ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD")
|
||||
}
|
||||
|
||||
val javadocJar by tasks.registering(Jar::class) {
|
||||
archiveClassifier.set("javadoc")
|
||||
}
|
||||
|
||||
fun getExtraString(name: String) = ext[name]?.toString()
|
||||
|
||||
publishing {
|
||||
// Configure maven central repository
|
||||
repositories {
|
||||
maven {
|
||||
name = "sonatype"
|
||||
setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
|
||||
credentials {
|
||||
username = getExtraString("ossrhUsername")
|
||||
password = getExtraString("ossrhPassword")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Configure all publications
|
||||
publications.withType<MavenPublication> {
|
||||
// Stub javadoc.jar artifact
|
||||
artifact(javadocJar.get())
|
||||
|
||||
// Provide artifacts information requited by Maven Central
|
||||
pom {
|
||||
name.set("Flatbuffers Kotlin")
|
||||
description.set("Memory Efficient Serialization Library")
|
||||
url.set("https://github.com/google/flatbuffers")
|
||||
|
||||
licenses {
|
||||
license {
|
||||
name.set("Apache License V2.0")
|
||||
url.set("https://raw.githubusercontent.com/google/flatbuffers/master/LICENSE")
|
||||
}
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
id.set("https://github.com/paulovap")
|
||||
name.set("Paulo Pinheiro")
|
||||
email.set("paulovictor.pinheiro@gmail.com")
|
||||
}
|
||||
developer {
|
||||
id.set("https://github.com/dbaileychess")
|
||||
name.set("Derek Bailey")
|
||||
email.set("dbaileychess@gmail.com")
|
||||
}
|
||||
}
|
||||
scm {
|
||||
url.set("https://github.com/google/flatbuffers")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Signing artifacts. Signing.* extra properties values will be used
|
||||
signing {
|
||||
sign(publishing.publications)
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkConfig
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
id("convention.publication")
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
[versions]
|
||||
kotlin = "1.8.21"
|
||||
# Version 1.9.10 fix
|
||||
# https://youtrack.jetbrains.com/issue/KT-60230/Native-unknown-options-iossimulatorversionmin-sdkversion-with-Xcode-15-beta-3
|
||||
kotlin = "1.9.10"
|
||||
plugin-kotlin = "1.6.10"
|
||||
plugin-gver = "0.42.0"
|
||||
kotlinx-benchmark = "0.4.8"
|
||||
junit = "4.12"
|
||||
gson = "2.8.5"
|
||||
gson = "2.8.9"
|
||||
moshi-kotlin = "1.11.0"
|
||||
|
||||
[libraries]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
rootProject.name = "flatbuffers-kotlin"
|
||||
includeBuild("convention-plugins")
|
||||
include("flatbuffers-kotlin")
|
||||
include("benchmark")
|
||||
|
||||
@@ -32,6 +32,6 @@ namespace Google.FlatBuffers
|
||||
Changes to the C# implementation need to be sure to change
|
||||
the version here and in the code generator on every possible
|
||||
incompatible change */
|
||||
public static void FLATBUFFERS_24_3_7() {}
|
||||
public static void FLATBUFFERS_24_12_23() {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.1;net6.0;net8.0</TargetFrameworks>
|
||||
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks>
|
||||
<Description>A cross-platform memory efficient serialization library</Description>
|
||||
<PackageVersion>24.3.7</PackageVersion>
|
||||
<PackageVersion>24.12.23</PackageVersion>
|
||||
<Authors>Google LLC</Authors>
|
||||
<PackageProjectUrl>https://github.com/google/flatbuffers</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/google/flatbuffers</RepositoryUrl>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "flatbuffers",
|
||||
"version": "24.3.7",
|
||||
"version": "24.12.23",
|
||||
"description": "Memory Efficient Serialization Library",
|
||||
"files": [
|
||||
"js/**/*.js",
|
||||
@@ -29,7 +29,7 @@
|
||||
"flatbuffers"
|
||||
],
|
||||
"author": "The FlatBuffers project",
|
||||
"license": "SEE LICENSE IN LICENSE",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/google/flatbuffers/issues"
|
||||
},
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
|
||||
# Placeholder, to be updated during the release process
|
||||
# by the setup.py
|
||||
__version__ = u"24.3.7"
|
||||
__version__ = u"24.12.23"
|
||||
|
||||
@@ -3,4 +3,4 @@ universal=1
|
||||
|
||||
[metadata]
|
||||
license_files =
|
||||
../license
|
||||
../LICENSE
|
||||
@@ -16,9 +16,8 @@ from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='flatbuffers',
|
||||
version='24.3.7',
|
||||
version='24.12.23',
|
||||
license='Apache 2.0',
|
||||
license_files='../LICENSE',
|
||||
author='Derek Bailey',
|
||||
author_email='derekbailey@google.com',
|
||||
url='https://google.github.io/flatbuffers/',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "flatbuffers"
|
||||
version = "24.3.7"
|
||||
version = "24.12.23"
|
||||
edition = "2018"
|
||||
authors = ["Robert Winslow <hello@rwinslow.com>", "FlatBuffers Maintainers"]
|
||||
license = "Apache-2.0"
|
||||
|
||||
@@ -52,7 +52,7 @@ pub use crate::builder::{Allocator, DefaultAllocator, FlatBufferBuilder};
|
||||
pub use crate::endian_scalar::{emplace_scalar, read_scalar, read_scalar_at, EndianScalar};
|
||||
pub use crate::follow::{Follow, FollowStart};
|
||||
pub use crate::primitives::*;
|
||||
pub use crate::push::Push;
|
||||
pub use crate::push::{Push, PushAlignment};
|
||||
pub use crate::table::{buffer_has_identifier, Table};
|
||||
pub use crate::vector::{follow_cast_ref, Vector, VectorIter};
|
||||
pub use crate::verifier::{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "flexbuffers"
|
||||
version = "2.0.0"
|
||||
version = "24.12.23"
|
||||
authors = ["Casper Neo <cneo@google.com>", "FlatBuffers Maintainers"]
|
||||
edition = "2018"
|
||||
license = "Apache-2.0"
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 24 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 3 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 7,
|
||||
FLATBUFFERS_VERSION_MINOR == 12 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 23,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace MyGame {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user