forked from BigfootDev/flatbuffers
Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee848a02e1 | ||
|
|
ef76b5ece4 | ||
|
|
1703662285 | ||
|
|
991b39edbe | ||
|
|
81799203f1 | ||
|
|
62e4d2e5b2 | ||
|
|
40758674b1 | ||
|
|
4e75867bd2 | ||
|
|
b17d59b18c | ||
|
|
b23493a7d2 | ||
|
|
b50b6be60a | ||
|
|
7bf83f5ea0 | ||
|
|
ca6381bcc8 | ||
|
|
3b8644d32c | ||
|
|
641fbe4658 | ||
|
|
5638a6a900 | ||
|
|
c2668fc0e2 | ||
|
|
b5802b57f2 | ||
|
|
06f2a3dce9 | ||
|
|
75af533e95 | ||
|
|
c95cf661af | ||
|
|
920f3827a0 | ||
|
|
81724e5b20 | ||
|
|
4d6a7aa8b7 | ||
|
|
e61b00359b | ||
|
|
74b5195089 | ||
|
|
07d9485146 | ||
|
|
82da3da3f6 | ||
|
|
a809a2d3f7 |
34
.github/workflows/build.yml
vendored
34
.github/workflows/build.yml
vendored
@@ -38,8 +38,10 @@ jobs:
|
||||
run: |
|
||||
chmod +x flatc
|
||||
./flatc --version
|
||||
- name: flatc tests
|
||||
run: python3 tests/flatc/main.py
|
||||
# - name: flatc tests
|
||||
# run: |
|
||||
# yarn global add esbuild
|
||||
# python3 tests/flatc/main.py
|
||||
- name: upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
@@ -143,8 +145,8 @@ jobs:
|
||||
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
||||
- name: test
|
||||
run: Release\flattests.exe
|
||||
- name: flatc tests
|
||||
run: python3 tests/flatc/main.py --flatc Release\flatc.exe
|
||||
# - name: flatc tests
|
||||
# run: python3 tests/flatc/main.py --flatc Release\flatc.exe
|
||||
- name: upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
@@ -245,8 +247,8 @@ jobs:
|
||||
run: |
|
||||
chmod +x Release/flatc
|
||||
Release/flatc --version
|
||||
- name: flatc tests
|
||||
run: python3 tests/flatc/main.py --flatc Release/flatc
|
||||
# - name: flatc tests
|
||||
# run: python3 tests/flatc/main.py --flatc Release/flatc
|
||||
- name: upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
@@ -343,6 +345,22 @@ jobs:
|
||||
- name: Generate gRPC
|
||||
run: scripts/check-grpc-generated-code.py
|
||||
|
||||
build-generator-windows:
|
||||
name: Check Generated Code on Windows
|
||||
runs-on: windows-2019
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.1
|
||||
- name: cmake
|
||||
run: cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_CPP17=ON -DFLATBUFFERS_STRICT_MODE=ON .
|
||||
- name: build
|
||||
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
||||
- name: Generate
|
||||
run: python3 scripts/check_generate_code.py --flatc Release\flatc.exe
|
||||
- name: Generate gRPC
|
||||
run: python3 scripts/check-grpc-generated-code.py --flatc Release\flatc.exe
|
||||
|
||||
build-benchmarks:
|
||||
name: Build Benchmarks (on Linux)
|
||||
runs-on: ubuntu-latest
|
||||
@@ -485,7 +503,9 @@ jobs:
|
||||
run: yarn compile
|
||||
- name: test
|
||||
working-directory: tests/ts
|
||||
run: python3 TypeScriptTest.py
|
||||
run: |
|
||||
yarn global add esbuild
|
||||
python3 TypeScriptTest.py
|
||||
|
||||
build-dart:
|
||||
name: Build Dart
|
||||
|
||||
@@ -44,6 +44,7 @@ filegroup(
|
||||
"include/flatbuffers/bfbs_generator.h",
|
||||
"include/flatbuffers/buffer.h",
|
||||
"include/flatbuffers/buffer_ref.h",
|
||||
"include/flatbuffers/code_generator.h",
|
||||
"include/flatbuffers/code_generators.h",
|
||||
"include/flatbuffers/default_allocator.h",
|
||||
"include/flatbuffers/detached_buffer.h",
|
||||
|
||||
@@ -4,6 +4,15 @@ 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.
|
||||
|
||||
## [23.1.21 (Jan 21 2023)](https://github.com/google/flatbuffers/releases/tag/v23.1.20)
|
||||
|
||||
* Reworked entry points for Typescript/Javascript and compatibility for single
|
||||
file build (#7510)
|
||||
|
||||
## [23.1.20 (Jan 20 2023)](https://github.com/google/flatbuffers/releases/tag/v23.1.20)
|
||||
|
||||
* Removed go.mod files after some versioning issues were being report (#7780).
|
||||
|
||||
## [23.1.4 (Jan 4 2023)](https://github.com/google/flatbuffers/releases/tag/v23.1.4)
|
||||
|
||||
* Major release! Just kidding, we are continuing the
|
||||
|
||||
@@ -438,14 +438,12 @@ endif()
|
||||
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
||||
|
||||
# Shared object version: "major.minor.micro"
|
||||
# - micro updated every release when there is no API/ABI changes
|
||||
# - minor updated when there are additions in API/ABI
|
||||
# - major (ABI number) updated when there are changes in ABI (or removals)
|
||||
set(FlatBuffers_Library_SONAME_MAJOR ${VERSION_MAJOR})
|
||||
set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
||||
# FlatBuffers use calendar-based versioning and do not provide any ABI
|
||||
# stability guarantees. Therefore, always use the full version as SOVERSION
|
||||
# in order to avoid breaking reverse dependencies on upgrades.
|
||||
set(FlatBuffers_Library_SONAME_FULL "${PROJECT_VERSION}")
|
||||
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
|
||||
SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}"
|
||||
SOVERSION "${FlatBuffers_Library_SONAME_FULL}"
|
||||
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
||||
if(FLATBUFFERS_ENABLE_PCH)
|
||||
add_pch_to_target(flatbuffers_shared include/flatbuffers/pch/pch.h)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
set(VERSION_MAJOR 23)
|
||||
set(VERSION_MINOR 1)
|
||||
set(VERSION_PATCH 4)
|
||||
set(VERSION_PATCH 21)
|
||||
set(VERSION_COMMIT 0)
|
||||
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||
|
||||
@@ -141,6 +141,7 @@ set(FlatBuffers_Library_SRCS
|
||||
include/flatbuffers/buffer_ref.h
|
||||
include/flatbuffers/default_allocator.h
|
||||
include/flatbuffers/detached_buffer.h
|
||||
include/flatbuffers/code_generator.h
|
||||
include/flatbuffers/flatbuffer_builder.h
|
||||
include/flatbuffers/flatbuffers.h
|
||||
include/flatbuffers/flexbuffers.h
|
||||
@@ -524,14 +525,12 @@ endif()
|
||||
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
||||
target_link_libraries(flatbuffers_shared PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||
# Shared object version: "major.minor.micro"
|
||||
# - micro updated every release when there is no API/ABI changes
|
||||
# - minor updated when there are additions in API/ABI
|
||||
# - major (ABI number) updated when there are changes in ABI (or removals)
|
||||
set(FlatBuffers_Library_SONAME_MAJOR ${VERSION_MAJOR})
|
||||
set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
||||
# FlatBuffers use calendar-based versioning and do not provide any ABI
|
||||
# stability guarantees. Therefore, always use the full version as SOVERSION
|
||||
# in order to avoid breaking reverse dependencies on upgrades.
|
||||
set(FlatBuffers_Library_SONAME_FULL "${PROJECT_VERSION}")
|
||||
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
|
||||
SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}"
|
||||
SOVERSION "${FlatBuffers_Library_SONAME_FULL}"
|
||||
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
||||
if(FLATBUFFERS_ENABLE_PCH)
|
||||
add_pch_to_target(flatbuffers_shared include/flatbuffers/pch/pch.h)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'FlatBuffers'
|
||||
s.version = '23.1.4'
|
||||
s.version = '23.1.21'
|
||||
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
||||
|
||||
s.description = "FlatBuffers is a cross platform serialization library architected for
|
||||
|
||||
@@ -32,6 +32,6 @@ let package = Package(
|
||||
.target(
|
||||
name: "FlatBuffers",
|
||||
dependencies: [],
|
||||
path: "swift/Sources")
|
||||
path: "swift/Sources"),
|
||||
])
|
||||
|
||||
|
||||
@@ -94,8 +94,12 @@ yarn_install(
|
||||
name = "npm",
|
||||
exports_directories_only = False,
|
||||
# Unfreeze to add/remove packages.
|
||||
frozen_lockfile = True,
|
||||
frozen_lockfile = False,
|
||||
package_json = "//:package.json",
|
||||
symlink_node_modules = False,
|
||||
yarn_lock = "//:yarn.lock",
|
||||
)
|
||||
|
||||
load("@build_bazel_rules_nodejs//toolchains/esbuild:esbuild_repositories.bzl", "esbuild_repositories")
|
||||
|
||||
esbuild_repositories(npm_repository = "npm")
|
||||
|
||||
@@ -2,9 +2,21 @@
|
||||
|
||||
package com.fbs.app
|
||||
|
||||
import java.nio.*
|
||||
import com.google.flatbuffers.BaseVector
|
||||
import com.google.flatbuffers.BooleanVector
|
||||
import com.google.flatbuffers.ByteVector
|
||||
import com.google.flatbuffers.Constants
|
||||
import com.google.flatbuffers.DoubleVector
|
||||
import com.google.flatbuffers.FlatBufferBuilder
|
||||
import com.google.flatbuffers.FloatVector
|
||||
import com.google.flatbuffers.LongVector
|
||||
import com.google.flatbuffers.StringVector
|
||||
import com.google.flatbuffers.Struct
|
||||
import com.google.flatbuffers.Table
|
||||
import com.google.flatbuffers.UnionVector
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import kotlin.math.sign
|
||||
import com.google.flatbuffers.*
|
||||
|
||||
@Suppress("unused")
|
||||
class Animal : Table() {
|
||||
@@ -36,7 +48,7 @@ class Animal : Table() {
|
||||
return if(o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
|
||||
}
|
||||
companion object {
|
||||
fun validateVersion() = Constants.FLATBUFFERS_23_1_4()
|
||||
fun validateVersion() = Constants.FLATBUFFERS_23_1_21()
|
||||
fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal())
|
||||
fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
|
||||
@@ -27,7 +27,7 @@ FetchContent_MakeAvailable(
|
||||
googlebenchmark
|
||||
)
|
||||
|
||||
set(CPP_BENCH_DIR cpp)
|
||||
set(CPP_BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cpp)
|
||||
set(CPP_FB_BENCH_DIR ${CPP_BENCH_DIR}/flatbuffers)
|
||||
set(CPP_RAW_BENCH_DIR ${CPP_BENCH_DIR}/raw)
|
||||
set(CPP_BENCH_FBS ${CPP_FB_BENCH_DIR}/bench.fbs)
|
||||
|
||||
@@ -7,7 +7,7 @@ Rules for building C++ flatbuffers with Bazel.
|
||||
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
flatc_path = "@com_github_google_flatbuffers//:flatc"
|
||||
TRUE_FLATC_PATH = "@com_github_google_flatbuffers//:flatc"
|
||||
|
||||
DEFAULT_INCLUDE_PATHS = [
|
||||
"./",
|
||||
@@ -16,6 +16,14 @@ DEFAULT_INCLUDE_PATHS = [
|
||||
"$(execpath @com_github_google_flatbuffers//:flatc).runfiles/com_github_google_flatbuffers",
|
||||
]
|
||||
|
||||
def default_include_paths(flatc_path):
|
||||
return [
|
||||
"./",
|
||||
"$(GENDIR)",
|
||||
"$(BINDIR)",
|
||||
"$(execpath %s).runfiles/com_github_google_flatbuffers" % (flatc_path),
|
||||
]
|
||||
|
||||
DEFAULT_FLATC_ARGS = [
|
||||
"--gen-object-api",
|
||||
"--gen-compare",
|
||||
@@ -32,13 +40,14 @@ def flatbuffer_library_public(
|
||||
language_flag,
|
||||
out_prefix = "",
|
||||
includes = [],
|
||||
include_paths = DEFAULT_INCLUDE_PATHS,
|
||||
include_paths = None,
|
||||
flatc_args = DEFAULT_FLATC_ARGS,
|
||||
reflection_name = "",
|
||||
reflection_visibility = None,
|
||||
compatible_with = None,
|
||||
restricted_to = None,
|
||||
target_compatible_with = None,
|
||||
flatc_path = "@com_github_google_flatbuffers//:flatc",
|
||||
output_to_bindir = False):
|
||||
"""Generates code files for reading/writing the given flatbuffers in the requested language using the public compiler.
|
||||
|
||||
@@ -62,6 +71,7 @@ def flatbuffer_library_public(
|
||||
for, instead of default-supported environments.
|
||||
target_compatible_with: Optional, The list of target platform constraints
|
||||
to use.
|
||||
flatc_path: Bazel target corresponding to the flatc compiler to use.
|
||||
output_to_bindir: Passed to genrule for output to bin directory.
|
||||
|
||||
|
||||
@@ -69,6 +79,8 @@ def flatbuffer_library_public(
|
||||
optionally a Fileset([reflection_name]) with all generated reflection
|
||||
binaries.
|
||||
"""
|
||||
if include_paths == None:
|
||||
include_paths = default_include_paths(flatc_path)
|
||||
include_paths_cmd = ["-I %s" % (s) for s in include_paths]
|
||||
|
||||
# '$(@D)' when given a single source target will give the appropriate
|
||||
@@ -80,7 +92,7 @@ def flatbuffer_library_public(
|
||||
genrule_cmd = " ".join([
|
||||
"SRCS=($(SRCS));",
|
||||
"for f in $${SRCS[@]:0:%s}; do" % len(srcs),
|
||||
"$(location %s)" % (flatc_path),
|
||||
"OUTPUT_FILE=\"$(OUTS)\" $(location %s)" % (flatc_path),
|
||||
" ".join(include_paths_cmd),
|
||||
" ".join(flatc_args),
|
||||
language_flag,
|
||||
@@ -104,7 +116,7 @@ def flatbuffer_library_public(
|
||||
reflection_genrule_cmd = " ".join([
|
||||
"SRCS=($(SRCS));",
|
||||
"for f in $${SRCS[@]:0:%s}; do" % len(srcs),
|
||||
"$(location %s)" % (flatc_path),
|
||||
"$(location %s)" % (TRUE_FLATC_PATH),
|
||||
"-b --schema",
|
||||
" ".join(flatc_args),
|
||||
" ".join(include_paths_cmd),
|
||||
@@ -122,7 +134,7 @@ def flatbuffer_library_public(
|
||||
srcs = srcs + includes,
|
||||
outs = reflection_outs,
|
||||
output_to_bindir = output_to_bindir,
|
||||
tools = [flatc_path],
|
||||
tools = [TRUE_FLATC_PATH],
|
||||
compatible_with = compatible_with,
|
||||
restricted_to = restricted_to,
|
||||
target_compatible_with = target_compatible_with,
|
||||
@@ -145,7 +157,7 @@ def flatbuffer_cc_library(
|
||||
out_prefix = "",
|
||||
deps = [],
|
||||
includes = [],
|
||||
include_paths = DEFAULT_INCLUDE_PATHS,
|
||||
include_paths = None,
|
||||
cc_include_paths = [],
|
||||
flatc_args = DEFAULT_FLATC_ARGS,
|
||||
visibility = None,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: flat_buffers
|
||||
version: 23.1.4
|
||||
version: 23.1.21
|
||||
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
|
||||
|
||||
@@ -90,7 +90,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.`
|
||||
|
||||
@@ -72,7 +72,10 @@ Now you can access values like this:
|
||||
In some cases it's necessary to modify values in an existing FlatBuffer in place (without creating a copy). For this reason, scalar fields of a Flatbuffer table or struct can be mutated.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.swift}
|
||||
let monster = Monster.getRootAsMonster(bb: ByteBuffer(data: data))
|
||||
var byteBuffer = ByteBuffer(bytes: data)
|
||||
// Get an accessor to the root object inside the buffer.
|
||||
let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
|
||||
// let monster: Monster = getRoot(byteBuffer: &byteBuffer)
|
||||
|
||||
if !monster.mutate(hp: 10) {
|
||||
fatalError("couldn't mutate")
|
||||
|
||||
@@ -321,9 +321,8 @@ Please be aware of the difference between `flatc` and `flatcc` tools.
|
||||
<div class="language-javascript">
|
||||
~~~{.sh}
|
||||
cd flatbuffers/samples
|
||||
./../flatc --ts monster.fbs
|
||||
# customize your TS -> JS transpilation
|
||||
tsc monster_generated.ts
|
||||
./../flatc --ts-flat-files --ts monster.fbs
|
||||
# produces ts/js modules and js bundle monster_generated.js
|
||||
~~~
|
||||
</div>
|
||||
<div class="language-typescript">
|
||||
@@ -2241,7 +2240,7 @@ before:
|
||||
~~~{.ts}
|
||||
// note: import flatbuffers with your desired import method
|
||||
|
||||
// note: the `./monster_generated.ts` file was previously generated by `flatc` above using the `monster.fbs` schema
|
||||
// note: the `./monster_generated.js` file was previously generated by `flatc` above using the `monster.fbs` schema
|
||||
import { MyGame } from './monster_generated';
|
||||
~~~
|
||||
</div>
|
||||
@@ -2472,10 +2471,10 @@ myGame.Monster monster = new myGame.Monster(data);
|
||||
<div class="language-swift">
|
||||
~~~{.swift}
|
||||
// create a ByteBuffer(:) from an [UInt8] or Data()
|
||||
let buf = // Get your data
|
||||
|
||||
var buf = // Get your data
|
||||
// Get an accessor to the root object inside the buffer.
|
||||
let monster = Monster.getRootAsMonster(bb: ByteBuffer(bytes: buf))
|
||||
let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
|
||||
// let monster: Monster = getRoot(byteBuffer: &byteBuffer)
|
||||
~~~
|
||||
</div>
|
||||
|
||||
|
||||
@@ -6,12 +6,10 @@ import FlatBuffers
|
||||
|
||||
public struct models_HelloReply: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
||||
static func validateVersion() { FlatBuffersVersion_23_1_21() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
public static func getRootAsHelloReply(bb: ByteBuffer) -> models_HelloReply { return models_HelloReply(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
||||
|
||||
private init(_ t: Table) { _accessor = t }
|
||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||
|
||||
@@ -55,12 +53,10 @@ extension models_HelloReply: Encodable {
|
||||
|
||||
public struct models_HelloRequest: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
||||
static func validateVersion() { FlatBuffersVersion_23_1_21() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
public static func getRootAsHelloRequest(bb: ByteBuffer) -> models_HelloRequest { return models_HelloRequest(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
||||
|
||||
private init(_ t: Table) { _accessor = t }
|
||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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,2 +1,3 @@
|
||||
export { HelloReply } from './models/hello-reply';
|
||||
export { HelloRequest } from './models/hello-request';
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export * as models from './models.js';
|
||||
|
||||
4
grpc/examples/ts/greeter/src/models.ts
Normal file
4
grpc/examples/ts/greeter/src/models.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export { HelloReply } from './models/hello-reply.js';
|
||||
export { HelloRequest } from './models/hello-request.js';
|
||||
@@ -17,6 +17,8 @@
|
||||
#ifndef FLATBUFFERS_ARRAY_H_
|
||||
#define FLATBUFFERS_ARRAY_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "flatbuffers/base.h"
|
||||
#include "flatbuffers/stl_emulation.h"
|
||||
#include "flatbuffers/vector.h"
|
||||
@@ -238,6 +240,14 @@ const Array<E, length> &CastToArrayOfEnum(const T (&arr)[length]) {
|
||||
return *reinterpret_cast<const Array<E, length> *>(arr);
|
||||
}
|
||||
|
||||
template<typename T, uint16_t length>
|
||||
bool operator==(const Array<T, length> &lhs,
|
||||
const Array<T, length> &rhs) noexcept {
|
||||
return std::addressof(lhs) == std::addressof(rhs) ||
|
||||
(lhs.size() == rhs.size() &&
|
||||
std::memcmp(lhs.Data(), rhs.Data(), rhs.size() * sizeof(T)) == 0);
|
||||
}
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // FLATBUFFERS_ARRAY_H_
|
||||
|
||||
@@ -140,7 +140,7 @@
|
||||
|
||||
#define FLATBUFFERS_VERSION_MAJOR 23
|
||||
#define FLATBUFFERS_VERSION_MINOR 1
|
||||
#define FLATBUFFERS_VERSION_REVISION 4
|
||||
#define FLATBUFFERS_VERSION_REVISION 21
|
||||
#define FLATBUFFERS_STRING_EXPAND(X) #X
|
||||
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
|
||||
namespace flatbuffers {
|
||||
|
||||
73
include/flatbuffers/code_generator.h
Normal file
73
include/flatbuffers/code_generator.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FLATBUFFERS_CODE_GENERATOR_H_
|
||||
#define FLATBUFFERS_CODE_GENERATOR_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "flatbuffers/idl.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
// An code generator interface for producing converting flatbuffer schema into
|
||||
// code.
|
||||
class CodeGenerator {
|
||||
public:
|
||||
virtual ~CodeGenerator() = default;
|
||||
|
||||
enum Status {
|
||||
OK = 0,
|
||||
ERROR = 1,
|
||||
NOT_IMPLEMENTED = 2,
|
||||
};
|
||||
|
||||
// Generate code from the provided `parser`.
|
||||
//
|
||||
// DEPRECATED: prefer using the other overload of GenerateCode for bfbs.
|
||||
virtual Status GenerateCode(const Parser &parser, const std::string &path,
|
||||
const std::string &filename) = 0;
|
||||
|
||||
// Generate code from the provided `buffer` of given `length`. The buffer is a
|
||||
// serialized reflection.fbs.
|
||||
virtual Status GenerateCode(const uint8_t *buffer, int64_t length) = 0;
|
||||
|
||||
virtual Status GenerateMakeRule(const Parser &parser, const std::string &path,
|
||||
const std::string &filename,
|
||||
std::string &output) = 0;
|
||||
|
||||
virtual Status GenerateGrpcCode(const Parser &parser, const std::string &path,
|
||||
const std::string &filename) = 0;
|
||||
|
||||
virtual bool IsSchemaOnly() const = 0;
|
||||
|
||||
virtual bool SupportsBfbsGeneration() const = 0;
|
||||
|
||||
virtual IDLOptions::Language Language() const = 0;
|
||||
virtual std::string LanguageName() const = 0;
|
||||
|
||||
protected:
|
||||
CodeGenerator() = default;
|
||||
|
||||
private:
|
||||
// Copying is not supported.
|
||||
CodeGenerator(const CodeGenerator &) = delete;
|
||||
CodeGenerator &operator=(const CodeGenerator &) = delete;
|
||||
};
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // FLATBUFFERS_CODE_GENERATOR_H_
|
||||
@@ -45,7 +45,7 @@ class DetachedBuffer {
|
||||
cur_(cur),
|
||||
size_(sz) {}
|
||||
|
||||
DetachedBuffer(DetachedBuffer &&other)
|
||||
DetachedBuffer(DetachedBuffer &&other) noexcept
|
||||
: allocator_(other.allocator_),
|
||||
own_allocator_(other.own_allocator_),
|
||||
buf_(other.buf_),
|
||||
@@ -55,7 +55,7 @@ class DetachedBuffer {
|
||||
other.reset();
|
||||
}
|
||||
|
||||
DetachedBuffer &operator=(DetachedBuffer &&other) {
|
||||
DetachedBuffer &operator=(DetachedBuffer &&other) noexcept {
|
||||
if (this == &other) return *this;
|
||||
|
||||
destroy();
|
||||
|
||||
@@ -98,7 +98,7 @@ class FlatBufferBuilder {
|
||||
}
|
||||
|
||||
/// @brief Move constructor for FlatBufferBuilder.
|
||||
FlatBufferBuilder(FlatBufferBuilder &&other)
|
||||
FlatBufferBuilder(FlatBufferBuilder &&other) noexcept
|
||||
: buf_(1024, nullptr, false, AlignOf<largest_scalar_t>()),
|
||||
num_field_loc(0),
|
||||
max_voffset_(0),
|
||||
@@ -116,7 +116,7 @@ class FlatBufferBuilder {
|
||||
}
|
||||
|
||||
/// @brief Move assignment operator for FlatBufferBuilder.
|
||||
FlatBufferBuilder &operator=(FlatBufferBuilder &&other) {
|
||||
FlatBufferBuilder &operator=(FlatBufferBuilder &&other) noexcept {
|
||||
// Move construct a temporary and swap idiom
|
||||
FlatBufferBuilder temp(std::move(other));
|
||||
Swap(temp);
|
||||
|
||||
@@ -19,18 +19,51 @@
|
||||
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "flatbuffers/bfbs_generator.h"
|
||||
#include "flatbuffers/code_generator.h"
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
#include "flatbuffers/idl.h"
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
// TODO(derekbailey): It would be better to define these as normal includes and
|
||||
// not as extern functions. But this can be done at a later time.
|
||||
extern std::unique_ptr<flatbuffers::CodeGenerator> NewCppCodeGenerator();
|
||||
|
||||
extern void LogCompilerWarn(const std::string &warn);
|
||||
extern void LogCompilerError(const std::string &err);
|
||||
|
||||
struct FlatCOptions {
|
||||
IDLOptions opts;
|
||||
|
||||
std::string program_name;
|
||||
|
||||
std::string output_path;
|
||||
|
||||
std::vector<std::string> filenames;
|
||||
|
||||
std::list<std::string> include_directories_storage;
|
||||
std::vector<const char *> include_directories;
|
||||
std::vector<const char *> conform_include_directories;
|
||||
std::vector<bool> generator_enabled;
|
||||
size_t binary_files_from = std::numeric_limits<size_t>::max();
|
||||
std::string conform_to_schema;
|
||||
std::string annotate_schema;
|
||||
bool any_generator = false;
|
||||
bool print_make_rules = false;
|
||||
bool raw_binary = false;
|
||||
bool schema_binary = false;
|
||||
bool grpc_enabled = false;
|
||||
bool requires_bfbs = false;
|
||||
|
||||
std::vector<std::shared_ptr<CodeGenerator>> generators;
|
||||
};
|
||||
|
||||
struct FlatCOption {
|
||||
std::string short_opt;
|
||||
std::string long_opt;
|
||||
@@ -85,15 +118,21 @@ class FlatCompiler {
|
||||
|
||||
explicit FlatCompiler(const InitParams ¶ms) : params_(params) {}
|
||||
|
||||
int Compile(int argc, const char **argv);
|
||||
bool RegisterCodeGenerator(const std::string& flag,
|
||||
std::shared_ptr<CodeGenerator> code_generator);
|
||||
|
||||
std::string GetShortUsageString(const char *program_name) const;
|
||||
std::string GetUsageString(const char *program_name) const;
|
||||
int Compile(const FlatCOptions &options);
|
||||
|
||||
std::string GetShortUsageString(const std::string &program_name) const;
|
||||
std::string GetUsageString(const std::string &program_name) const;
|
||||
|
||||
// Parse the FlatC options from command line arguments.
|
||||
FlatCOptions ParseFromCommandLineArguments(int argc, const char **argv);
|
||||
|
||||
private:
|
||||
void ParseFile(flatbuffers::Parser &parser, const std::string &filename,
|
||||
const std::string &contents,
|
||||
std::vector<const char *> &include_directories) const;
|
||||
const std::vector<const char *> &include_directories) const;
|
||||
|
||||
void LoadBinarySchema(Parser &parser, const std::string &filename,
|
||||
const std::string &contents);
|
||||
@@ -105,9 +144,18 @@ class FlatCompiler {
|
||||
|
||||
void AnnotateBinaries(const uint8_t *binary_schema,
|
||||
uint64_t binary_schema_size,
|
||||
const std::string & schema_filename,
|
||||
const std::string &schema_filename,
|
||||
const std::vector<std::string> &binary_files);
|
||||
|
||||
void ValidateOptions(const FlatCOptions &options);
|
||||
|
||||
Parser GetConformParser(const FlatCOptions &options);
|
||||
|
||||
std::unique_ptr<Parser> GenerateCode(const FlatCOptions &options,
|
||||
Parser &conform_parser);
|
||||
|
||||
std::map<std::string, std::shared_ptr<CodeGenerator>> code_generators_;
|
||||
|
||||
InitParams params_;
|
||||
};
|
||||
|
||||
|
||||
@@ -1845,7 +1845,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
uint8_t len = 0;
|
||||
auto vtype = ToFixedTypedVectorElementType(r.type_, &len);
|
||||
if (!VerifyType(vtype)) return false;
|
||||
return VerifyFromPointer(p, r.byte_width_ * len);
|
||||
return VerifyFromPointer(p, static_cast<size_t>(r.byte_width_) * len);
|
||||
}
|
||||
default: return false;
|
||||
}
|
||||
|
||||
@@ -297,7 +297,8 @@ struct FieldDef : public Definition {
|
||||
flexbuffer(false),
|
||||
presence(kDefault),
|
||||
nested_flatbuffer(nullptr),
|
||||
padding(0) {}
|
||||
padding(0),
|
||||
sibling_union_field(nullptr) {}
|
||||
|
||||
Offset<reflection::Field> Serialize(FlatBufferBuilder *builder, uint16_t id,
|
||||
const Parser &parser) const;
|
||||
@@ -342,6 +343,12 @@ struct FieldDef : public Definition {
|
||||
|
||||
StructDef *nested_flatbuffer; // This field contains nested FlatBuffer data.
|
||||
size_t padding; // Bytes to always pad after this field.
|
||||
|
||||
// sibling_union_field is always set to nullptr. The only exception is
|
||||
// when FieldDef is a union field or an union type field. Therefore,
|
||||
// sibling_union_field on a union field points to the union type field
|
||||
// and vice-versa.
|
||||
FieldDef *sibling_union_field;
|
||||
};
|
||||
|
||||
struct StructDef : public Definition {
|
||||
@@ -598,6 +605,7 @@ struct IDLOptions {
|
||||
bool output_enum_identifiers;
|
||||
bool prefixed_enums;
|
||||
bool scoped_enums;
|
||||
bool emit_min_max_enum_values;
|
||||
bool swift_implementation_only;
|
||||
bool include_dependence_headers;
|
||||
bool mutable_buffer;
|
||||
@@ -650,7 +658,9 @@ struct IDLOptions {
|
||||
bool json_nested_flatbuffers;
|
||||
bool json_nested_flexbuffers;
|
||||
bool json_nested_legacy_flatbuffers;
|
||||
bool ts_flat_file;
|
||||
bool ts_flat_files;
|
||||
bool ts_entry_points;
|
||||
bool ts_no_import_ext;
|
||||
bool no_leak_private_annotations;
|
||||
bool require_json_eof;
|
||||
|
||||
@@ -711,6 +721,7 @@ struct IDLOptions {
|
||||
output_enum_identifiers(true),
|
||||
prefixed_enums(true),
|
||||
scoped_enums(false),
|
||||
emit_min_max_enum_values(true),
|
||||
swift_implementation_only(false),
|
||||
include_dependence_headers(true),
|
||||
mutable_buffer(false),
|
||||
@@ -753,7 +764,9 @@ struct IDLOptions {
|
||||
json_nested_flatbuffers(true),
|
||||
json_nested_flexbuffers(true),
|
||||
json_nested_legacy_flatbuffers(false),
|
||||
ts_flat_file(false),
|
||||
ts_flat_files(false),
|
||||
ts_entry_points(false),
|
||||
ts_no_import_ext(false),
|
||||
no_leak_private_annotations(false),
|
||||
require_json_eof(true),
|
||||
mini_reflect(IDLOptions::kNone),
|
||||
@@ -792,7 +805,7 @@ struct ParserState {
|
||||
FLATBUFFERS_ASSERT(cursor_ && line_start_ && cursor_ >= line_start_);
|
||||
return static_cast<int64_t>(cursor_ - line_start_);
|
||||
}
|
||||
|
||||
|
||||
const char *prev_cursor_;
|
||||
const char *cursor_;
|
||||
const char *line_start_;
|
||||
@@ -899,6 +912,13 @@ class Parser : public ParserState {
|
||||
known_attributes_["private"] = true;
|
||||
}
|
||||
|
||||
// Copying is not allowed
|
||||
Parser(const Parser &) = delete;
|
||||
Parser &operator=(const Parser &) = delete;
|
||||
|
||||
Parser(Parser &&) = default;
|
||||
Parser &operator=(Parser &&) = default;
|
||||
|
||||
~Parser() {
|
||||
for (auto it = namespaces_.begin(); it != namespaces_.end(); ++it) {
|
||||
delete *it;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -31,6 +31,7 @@
|
||||
# include <stdio.h>
|
||||
#endif // FLATBUFFERS_PREFER_PRINTF
|
||||
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
@@ -313,6 +314,7 @@ inline bool StringToFloatImpl(T *val, const char *const str) {
|
||||
strtoval_impl(val, str, const_cast<char **>(&end));
|
||||
auto done = (end != str) && (*end == '\0');
|
||||
if (!done) *val = 0; // erase partial result
|
||||
if (done && std::isnan(*val)) { *val = std::numeric_limits<T>::quiet_NaN(); }
|
||||
return done;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class vector_downward {
|
||||
cur_(nullptr),
|
||||
scratch_(nullptr) {}
|
||||
|
||||
vector_downward(vector_downward &&other)
|
||||
vector_downward(vector_downward &&other) noexcept
|
||||
// clang-format on
|
||||
: allocator_(other.allocator_),
|
||||
own_allocator_(other.own_allocator_),
|
||||
@@ -66,7 +66,7 @@ class vector_downward {
|
||||
other.scratch_ = nullptr;
|
||||
}
|
||||
|
||||
vector_downward &operator=(vector_downward &&other) {
|
||||
vector_downward &operator=(vector_downward &&other) noexcept {
|
||||
// Move construct a temporary and swap idiom
|
||||
vector_downward temp(std::move(other));
|
||||
swap(temp);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.google.flatbuffers</groupId>
|
||||
<artifactId>flatbuffers-java</artifactId>
|
||||
<version>23.1.4</version>
|
||||
<version>23.1.21</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_23_1_4() {}
|
||||
public static void FLATBUFFERS_23_1_21() {}
|
||||
}
|
||||
|
||||
/// @endcond
|
||||
|
||||
@@ -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_23_1_4() {}
|
||||
public static void FLATBUFFERS_23_1_21() {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.1;netstandard2.0;net46</TargetFrameworks>
|
||||
<Description>A cross-platform memory efficient serialization library</Description>
|
||||
<PackageVersion>23.1.4</PackageVersion>
|
||||
<PackageVersion>23.1.21</PackageVersion>
|
||||
<Authors>Google LLC</Authors>
|
||||
<PackageProjectUrl>https://github.com/google/flatbuffers</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/google/flatbuffers</RepositoryUrl>
|
||||
|
||||
28
package.json
28
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "flatbuffers",
|
||||
"version": "23.1.4",
|
||||
"version": "23.1.21",
|
||||
"description": "Memory Efficient Serialization Library",
|
||||
"files": [
|
||||
"js/**/*.js",
|
||||
@@ -9,8 +9,20 @@
|
||||
"mjs/**/*.d.ts",
|
||||
"ts/**/*.ts"
|
||||
],
|
||||
"main": "js/index.js",
|
||||
"module": "mjs/index.js",
|
||||
"main": "js/flatbuffers.js",
|
||||
"module": "mjs/flatbuffers.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"node": {
|
||||
"import": "./mjs/flatbuffers.js",
|
||||
"require": "./js/flatbuffers.js"
|
||||
},
|
||||
"default": "./js/flatbuffers.js"
|
||||
},
|
||||
"./js/flexbuffers.js": {
|
||||
"default": "./js/flexbuffers.js"
|
||||
}
|
||||
},
|
||||
"directories": {
|
||||
"doc": "docs",
|
||||
"test": "tests"
|
||||
@@ -18,7 +30,7 @@
|
||||
"scripts": {
|
||||
"test": "npm run compile && cd tests/ts && python3 ./TypeScriptTest.py",
|
||||
"lint": "eslint ts",
|
||||
"compile": "tsc && tsc -p tsconfig.mjs.json && rollup -c",
|
||||
"compile": "tsc && tsc -p tsconfig.mjs.json && esbuild js/flatbuffers.js --minify --global-name=flatbuffers --bundle --outfile=js/flatbuffers.min.js",
|
||||
"prepublishOnly": "npm install --only=dev && npm run compile"
|
||||
},
|
||||
"repository": {
|
||||
@@ -38,10 +50,10 @@
|
||||
"devDependencies": {
|
||||
"@bazel/typescript": "5.2.0",
|
||||
"@types/node": "18.7.16",
|
||||
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
||||
"@typescript-eslint/parser": "^5.36.2",
|
||||
"eslint": "^8.23.1",
|
||||
"rollup": "^2.79.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.46.0",
|
||||
"@typescript-eslint/parser": "^5.46.0",
|
||||
"esbuild": "^0.16.4",
|
||||
"eslint": "^8.29.0",
|
||||
"typescript": "^4.8.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
|
||||
# Placeholder, to be updated during the release process
|
||||
# by the setup.py
|
||||
__version__ = u"23.1.4"
|
||||
__version__ = u"23.1.21"
|
||||
|
||||
@@ -75,7 +75,7 @@ class BitWidth(enum.IntEnum):
|
||||
@staticmethod
|
||||
def F(value):
|
||||
"""Returns the `BitWidth` to encode floating point value."""
|
||||
if struct.unpack('f', struct.pack('f', value))[0] == value:
|
||||
if struct.unpack('<f', struct.pack('<f', value))[0] == value:
|
||||
return BitWidth.W32
|
||||
return BitWidth.W64
|
||||
|
||||
@@ -95,20 +95,20 @@ F = {4: 'f', 8: 'd'} # Floating point formats
|
||||
|
||||
|
||||
def _Unpack(fmt, buf):
|
||||
return struct.unpack(fmt[len(buf)], buf)[0]
|
||||
return struct.unpack('<%s' % fmt[len(buf)], buf)[0]
|
||||
|
||||
|
||||
def _UnpackVector(fmt, buf, length):
|
||||
byte_width = len(buf) // length
|
||||
return struct.unpack('%d%s' % (length, fmt[byte_width]), buf)
|
||||
return struct.unpack('<%d%s' % (length, fmt[byte_width]), buf)
|
||||
|
||||
|
||||
def _Pack(fmt, value, byte_width):
|
||||
return struct.pack(fmt[byte_width], value)
|
||||
return struct.pack('<%s' % fmt[byte_width], value)
|
||||
|
||||
|
||||
def _PackVector(fmt, values, byte_width):
|
||||
return struct.pack('%d%s' % (len(values), fmt[byte_width]), *values)
|
||||
return struct.pack('<%d%s' % (len(values), fmt[byte_width]), *values)
|
||||
|
||||
|
||||
def _Mutate(fmt, buf, value, byte_width, value_bit_width):
|
||||
|
||||
@@ -16,7 +16,7 @@ from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='flatbuffers',
|
||||
version='23.1.4',
|
||||
version='23.1.21',
|
||||
license='Apache 2.0',
|
||||
license_files='../LICENSE.txt',
|
||||
author='Derek Bailey',
|
||||
|
||||
@@ -44,6 +44,10 @@ Code generation and runtime libraries for many popular languages.
|
||||
1. TypeScript - [NPM](https://www.npmjs.com/package/flatbuffers)
|
||||
1. Nim
|
||||
|
||||
## Versioning
|
||||
|
||||
FlatBuffers does not follow traditional Semver versioning (see [rationale](https://github.com/google/flatbuffers/wiki/Versioning)) but rather uses a format of the date of the release.
|
||||
|
||||
## Contribution
|
||||
|
||||
* [FlatBuffers Issues Tracker][] to submit an issue.
|
||||
|
||||
@@ -11,6 +11,5 @@ flatbuffer_ts_library(
|
||||
name = "reflection_ts_fbs",
|
||||
package_name = "flatbuffers_reflection",
|
||||
srcs = [":reflection.fbs"],
|
||||
include_reflection = False,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
export default {
|
||||
input: 'mjs/index.js',
|
||||
output: {
|
||||
file: 'flatbuffers.js',
|
||||
format: 'iife',
|
||||
name: 'flatbuffers'
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "flatbuffers"
|
||||
version = "23.1.4"
|
||||
version = "23.1.21"
|
||||
edition = "2018"
|
||||
authors = ["Robert Winslow <hello@rwinslow.com>", "FlatBuffers Maintainers"]
|
||||
license = "Apache-2.0"
|
||||
|
||||
@@ -24,6 +24,7 @@ import MyGame.Sample.Weapon
|
||||
|
||||
import com.google.flatbuffers.FlatBufferBuilder
|
||||
|
||||
@kotlin.ExperimentalUnsignedTypes
|
||||
class SampleBinary {
|
||||
|
||||
companion object {
|
||||
@@ -45,7 +46,7 @@ class SampleBinary {
|
||||
|
||||
// Serialize the FlatBuffer data.
|
||||
val name = builder.createString("Orc")
|
||||
val treasure = byteArrayOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
|
||||
val treasure = byteArrayOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).asUByteArray()
|
||||
val inv = Monster.createInventoryVector(builder, treasure)
|
||||
val weapons = Monster.createWeaponsVector(builder, weaps)
|
||||
val pos = Vec3.createVec3(builder, 1.0f, 2.0f, 3.0f)
|
||||
@@ -85,7 +86,7 @@ class SampleBinary {
|
||||
|
||||
// Get and test the `inventory` FlatBuffer `vector`.
|
||||
for (i in 0 until monster.inventoryLength) {
|
||||
assert(monster.inventory(i) == i.toByte().toInt())
|
||||
assert(monster.inventory(i) == i.toUByte())
|
||||
}
|
||||
|
||||
// Get and test the `weapons` FlatBuffer `vector` of `table`s.
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 23 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 1 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 4,
|
||||
FLATBUFFERS_VERSION_REVISION == 21,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace MyGame {
|
||||
@@ -33,11 +33,11 @@ bool operator!=(const MonsterT &lhs, const MonsterT &rhs);
|
||||
bool operator==(const WeaponT &lhs, const WeaponT &rhs);
|
||||
bool operator!=(const WeaponT &lhs, const WeaponT &rhs);
|
||||
|
||||
inline const flatbuffers::TypeTable *Vec3TypeTable();
|
||||
inline const ::flatbuffers::TypeTable *Vec3TypeTable();
|
||||
|
||||
inline const flatbuffers::TypeTable *MonsterTypeTable();
|
||||
inline const ::flatbuffers::TypeTable *MonsterTypeTable();
|
||||
|
||||
inline const flatbuffers::TypeTable *WeaponTypeTable();
|
||||
inline const ::flatbuffers::TypeTable *WeaponTypeTable();
|
||||
|
||||
enum Color : int8_t {
|
||||
Color_Red = 0,
|
||||
@@ -67,7 +67,7 @@ inline const char * const *EnumNamesColor() {
|
||||
}
|
||||
|
||||
inline const char *EnumNameColor(Color e) {
|
||||
if (flatbuffers::IsOutRange(e, Color_Red, Color_Blue)) return "";
|
||||
if (::flatbuffers::IsOutRange(e, Color_Red, Color_Blue)) return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesColor()[index];
|
||||
}
|
||||
@@ -97,7 +97,7 @@ inline const char * const *EnumNamesEquipment() {
|
||||
}
|
||||
|
||||
inline const char *EnumNameEquipment(Equipment e) {
|
||||
if (flatbuffers::IsOutRange(e, Equipment_NONE, Equipment_Weapon)) return "";
|
||||
if (::flatbuffers::IsOutRange(e, Equipment_NONE, Equipment_Weapon)) return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesEquipment()[index];
|
||||
}
|
||||
@@ -145,8 +145,8 @@ struct EquipmentUnion {
|
||||
}
|
||||
}
|
||||
|
||||
static void *UnPack(const void *obj, Equipment type, const flatbuffers::resolver_function_t *resolver);
|
||||
flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
|
||||
static void *UnPack(const void *obj, Equipment type, const ::flatbuffers::resolver_function_t *resolver);
|
||||
::flatbuffers::Offset<void> Pack(::flatbuffers::FlatBufferBuilder &_fbb, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
|
||||
|
||||
MyGame::Sample::WeaponT *AsWeapon() {
|
||||
return type == Equipment_Weapon ?
|
||||
@@ -179,8 +179,8 @@ inline bool operator!=(const EquipmentUnion &lhs, const EquipmentUnion &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
bool VerifyEquipment(flatbuffers::Verifier &verifier, const void *obj, Equipment type);
|
||||
bool VerifyEquipmentVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types);
|
||||
bool VerifyEquipment(::flatbuffers::Verifier &verifier, const void *obj, Equipment type);
|
||||
bool VerifyEquipmentVector(::flatbuffers::Verifier &verifier, const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values, const ::flatbuffers::Vector<uint8_t> *types);
|
||||
|
||||
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Vec3 FLATBUFFERS_FINAL_CLASS {
|
||||
private:
|
||||
@@ -189,7 +189,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Vec3 FLATBUFFERS_FINAL_CLASS {
|
||||
float z_;
|
||||
|
||||
public:
|
||||
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return Vec3TypeTable();
|
||||
}
|
||||
Vec3()
|
||||
@@ -198,27 +198,27 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Vec3 FLATBUFFERS_FINAL_CLASS {
|
||||
z_(0) {
|
||||
}
|
||||
Vec3(float _x, float _y, float _z)
|
||||
: x_(flatbuffers::EndianScalar(_x)),
|
||||
y_(flatbuffers::EndianScalar(_y)),
|
||||
z_(flatbuffers::EndianScalar(_z)) {
|
||||
: x_(::flatbuffers::EndianScalar(_x)),
|
||||
y_(::flatbuffers::EndianScalar(_y)),
|
||||
z_(::flatbuffers::EndianScalar(_z)) {
|
||||
}
|
||||
float x() const {
|
||||
return flatbuffers::EndianScalar(x_);
|
||||
return ::flatbuffers::EndianScalar(x_);
|
||||
}
|
||||
void mutate_x(float _x) {
|
||||
flatbuffers::WriteScalar(&x_, _x);
|
||||
::flatbuffers::WriteScalar(&x_, _x);
|
||||
}
|
||||
float y() const {
|
||||
return flatbuffers::EndianScalar(y_);
|
||||
return ::flatbuffers::EndianScalar(y_);
|
||||
}
|
||||
void mutate_y(float _y) {
|
||||
flatbuffers::WriteScalar(&y_, _y);
|
||||
::flatbuffers::WriteScalar(&y_, _y);
|
||||
}
|
||||
float z() const {
|
||||
return flatbuffers::EndianScalar(z_);
|
||||
return ::flatbuffers::EndianScalar(z_);
|
||||
}
|
||||
void mutate_z(float _z) {
|
||||
flatbuffers::WriteScalar(&z_, _z);
|
||||
::flatbuffers::WriteScalar(&z_, _z);
|
||||
}
|
||||
};
|
||||
FLATBUFFERS_STRUCT_END(Vec3, 12);
|
||||
@@ -235,7 +235,7 @@ inline bool operator!=(const Vec3 &lhs, const Vec3 &rhs) {
|
||||
}
|
||||
|
||||
|
||||
struct MonsterT : public flatbuffers::NativeTable {
|
||||
struct MonsterT : public ::flatbuffers::NativeTable {
|
||||
typedef Monster TableType;
|
||||
flatbuffers::unique_ptr<MyGame::Sample::Vec3> pos{};
|
||||
int16_t mana = 150;
|
||||
@@ -252,10 +252,10 @@ struct MonsterT : public flatbuffers::NativeTable {
|
||||
MonsterT &operator=(MonsterT o) FLATBUFFERS_NOEXCEPT;
|
||||
};
|
||||
|
||||
struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef MonsterT NativeTableType;
|
||||
typedef MonsterBuilder Builder;
|
||||
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return MonsterTypeTable();
|
||||
}
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
@@ -288,17 +288,17 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
bool mutate_hp(int16_t _hp = 100) {
|
||||
return SetField<int16_t>(VT_HP, _hp, 100);
|
||||
}
|
||||
const flatbuffers::String *name() const {
|
||||
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
||||
const ::flatbuffers::String *name() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_NAME);
|
||||
}
|
||||
flatbuffers::String *mutable_name() {
|
||||
return GetPointer<flatbuffers::String *>(VT_NAME);
|
||||
::flatbuffers::String *mutable_name() {
|
||||
return GetPointer<::flatbuffers::String *>(VT_NAME);
|
||||
}
|
||||
const flatbuffers::Vector<uint8_t> *inventory() const {
|
||||
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_INVENTORY);
|
||||
const ::flatbuffers::Vector<uint8_t> *inventory() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<uint8_t> *>(VT_INVENTORY);
|
||||
}
|
||||
flatbuffers::Vector<uint8_t> *mutable_inventory() {
|
||||
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_INVENTORY);
|
||||
::flatbuffers::Vector<uint8_t> *mutable_inventory() {
|
||||
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_INVENTORY);
|
||||
}
|
||||
MyGame::Sample::Color color() const {
|
||||
return static_cast<MyGame::Sample::Color>(GetField<int8_t>(VT_COLOR, 2));
|
||||
@@ -306,11 +306,11 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
bool mutate_color(MyGame::Sample::Color _color = static_cast<MyGame::Sample::Color>(2)) {
|
||||
return SetField<int8_t>(VT_COLOR, static_cast<int8_t>(_color), 2);
|
||||
}
|
||||
const flatbuffers::Vector<flatbuffers::Offset<MyGame::Sample::Weapon>> *weapons() const {
|
||||
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<MyGame::Sample::Weapon>> *>(VT_WEAPONS);
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Sample::Weapon>> *weapons() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Sample::Weapon>> *>(VT_WEAPONS);
|
||||
}
|
||||
flatbuffers::Vector<flatbuffers::Offset<MyGame::Sample::Weapon>> *mutable_weapons() {
|
||||
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<MyGame::Sample::Weapon>> *>(VT_WEAPONS);
|
||||
::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Sample::Weapon>> *mutable_weapons() {
|
||||
return GetPointer<::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Sample::Weapon>> *>(VT_WEAPONS);
|
||||
}
|
||||
MyGame::Sample::Equipment equipped_type() const {
|
||||
return static_cast<MyGame::Sample::Equipment>(GetField<uint8_t>(VT_EQUIPPED_TYPE, 0));
|
||||
@@ -325,13 +325,13 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
void *mutable_equipped() {
|
||||
return GetPointer<void *>(VT_EQUIPPED);
|
||||
}
|
||||
const flatbuffers::Vector<const MyGame::Sample::Vec3 *> *path() const {
|
||||
return GetPointer<const flatbuffers::Vector<const MyGame::Sample::Vec3 *> *>(VT_PATH);
|
||||
const ::flatbuffers::Vector<const MyGame::Sample::Vec3 *> *path() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<const MyGame::Sample::Vec3 *> *>(VT_PATH);
|
||||
}
|
||||
flatbuffers::Vector<const MyGame::Sample::Vec3 *> *mutable_path() {
|
||||
return GetPointer<flatbuffers::Vector<const MyGame::Sample::Vec3 *> *>(VT_PATH);
|
||||
::flatbuffers::Vector<const MyGame::Sample::Vec3 *> *mutable_path() {
|
||||
return GetPointer<::flatbuffers::Vector<const MyGame::Sample::Vec3 *> *>(VT_PATH);
|
||||
}
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<MyGame::Sample::Vec3>(verifier, VT_POS, 4) &&
|
||||
VerifyField<int16_t>(verifier, VT_MANA, 2) &&
|
||||
@@ -351,9 +351,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
verifier.VerifyVector(path()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
MonsterT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
void UnPackTo(MonsterT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
static flatbuffers::Offset<Monster> Pack(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT* _o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
MonsterT *UnPack(const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
void UnPackTo(MonsterT *_o, const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
static ::flatbuffers::Offset<Monster> Pack(::flatbuffers::FlatBufferBuilder &_fbb, const MonsterT* _o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
};
|
||||
|
||||
template<> inline const MyGame::Sample::Weapon *Monster::equipped_as<MyGame::Sample::Weapon>() const {
|
||||
@@ -362,8 +362,8 @@ template<> inline const MyGame::Sample::Weapon *Monster::equipped_as<MyGame::Sam
|
||||
|
||||
struct MonsterBuilder {
|
||||
typedef Monster Table;
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_pos(const MyGame::Sample::Vec3 *pos) {
|
||||
fbb_.AddStruct(Monster::VT_POS, pos);
|
||||
}
|
||||
@@ -373,50 +373,50 @@ struct MonsterBuilder {
|
||||
void add_hp(int16_t hp) {
|
||||
fbb_.AddElement<int16_t>(Monster::VT_HP, hp, 100);
|
||||
}
|
||||
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
||||
void add_name(::flatbuffers::Offset<::flatbuffers::String> name) {
|
||||
fbb_.AddOffset(Monster::VT_NAME, name);
|
||||
}
|
||||
void add_inventory(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> inventory) {
|
||||
void add_inventory(::flatbuffers::Offset<::flatbuffers::Vector<uint8_t>> inventory) {
|
||||
fbb_.AddOffset(Monster::VT_INVENTORY, inventory);
|
||||
}
|
||||
void add_color(MyGame::Sample::Color color) {
|
||||
fbb_.AddElement<int8_t>(Monster::VT_COLOR, static_cast<int8_t>(color), 2);
|
||||
}
|
||||
void add_weapons(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<MyGame::Sample::Weapon>>> weapons) {
|
||||
void add_weapons(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Sample::Weapon>>> weapons) {
|
||||
fbb_.AddOffset(Monster::VT_WEAPONS, weapons);
|
||||
}
|
||||
void add_equipped_type(MyGame::Sample::Equipment equipped_type) {
|
||||
fbb_.AddElement<uint8_t>(Monster::VT_EQUIPPED_TYPE, static_cast<uint8_t>(equipped_type), 0);
|
||||
}
|
||||
void add_equipped(flatbuffers::Offset<void> equipped) {
|
||||
void add_equipped(::flatbuffers::Offset<void> equipped) {
|
||||
fbb_.AddOffset(Monster::VT_EQUIPPED, equipped);
|
||||
}
|
||||
void add_path(flatbuffers::Offset<flatbuffers::Vector<const MyGame::Sample::Vec3 *>> path) {
|
||||
void add_path(::flatbuffers::Offset<::flatbuffers::Vector<const MyGame::Sample::Vec3 *>> path) {
|
||||
fbb_.AddOffset(Monster::VT_PATH, path);
|
||||
}
|
||||
explicit MonsterBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||
explicit MonsterBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
flatbuffers::Offset<Monster> Finish() {
|
||||
::flatbuffers::Offset<Monster> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Monster>(end);
|
||||
auto o = ::flatbuffers::Offset<Monster>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline flatbuffers::Offset<Monster> CreateMonster(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
inline ::flatbuffers::Offset<Monster> CreateMonster(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const MyGame::Sample::Vec3 *pos = nullptr,
|
||||
int16_t mana = 150,
|
||||
int16_t hp = 100,
|
||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
||||
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> inventory = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::String> name = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<uint8_t>> inventory = 0,
|
||||
MyGame::Sample::Color color = MyGame::Sample::Color_Blue,
|
||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<MyGame::Sample::Weapon>>> weapons = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Sample::Weapon>>> weapons = 0,
|
||||
MyGame::Sample::Equipment equipped_type = MyGame::Sample::Equipment_NONE,
|
||||
flatbuffers::Offset<void> equipped = 0,
|
||||
flatbuffers::Offset<flatbuffers::Vector<const MyGame::Sample::Vec3 *>> path = 0) {
|
||||
::flatbuffers::Offset<void> equipped = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<const MyGame::Sample::Vec3 *>> path = 0) {
|
||||
MonsterBuilder builder_(_fbb);
|
||||
builder_.add_path(path);
|
||||
builder_.add_equipped(equipped);
|
||||
@@ -431,21 +431,21 @@ inline flatbuffers::Offset<Monster> CreateMonster(
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<Monster> CreateMonsterDirect(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
inline ::flatbuffers::Offset<Monster> CreateMonsterDirect(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const MyGame::Sample::Vec3 *pos = nullptr,
|
||||
int16_t mana = 150,
|
||||
int16_t hp = 100,
|
||||
const char *name = nullptr,
|
||||
const std::vector<uint8_t> *inventory = nullptr,
|
||||
MyGame::Sample::Color color = MyGame::Sample::Color_Blue,
|
||||
const std::vector<flatbuffers::Offset<MyGame::Sample::Weapon>> *weapons = nullptr,
|
||||
const std::vector<::flatbuffers::Offset<MyGame::Sample::Weapon>> *weapons = nullptr,
|
||||
MyGame::Sample::Equipment equipped_type = MyGame::Sample::Equipment_NONE,
|
||||
flatbuffers::Offset<void> equipped = 0,
|
||||
::flatbuffers::Offset<void> equipped = 0,
|
||||
const std::vector<MyGame::Sample::Vec3> *path = nullptr) {
|
||||
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||
auto inventory__ = inventory ? _fbb.CreateVector<uint8_t>(*inventory) : 0;
|
||||
auto weapons__ = weapons ? _fbb.CreateVector<flatbuffers::Offset<MyGame::Sample::Weapon>>(*weapons) : 0;
|
||||
auto weapons__ = weapons ? _fbb.CreateVector<::flatbuffers::Offset<MyGame::Sample::Weapon>>(*weapons) : 0;
|
||||
auto path__ = path ? _fbb.CreateVectorOfStructs<MyGame::Sample::Vec3>(*path) : 0;
|
||||
return MyGame::Sample::CreateMonster(
|
||||
_fbb,
|
||||
@@ -461,29 +461,29 @@ inline flatbuffers::Offset<Monster> CreateMonsterDirect(
|
||||
path__);
|
||||
}
|
||||
|
||||
flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
::flatbuffers::Offset<Monster> CreateMonster(::flatbuffers::FlatBufferBuilder &_fbb, const MonsterT *_o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
|
||||
struct WeaponT : public flatbuffers::NativeTable {
|
||||
struct WeaponT : public ::flatbuffers::NativeTable {
|
||||
typedef Weapon TableType;
|
||||
std::string name{};
|
||||
int16_t damage = 0;
|
||||
};
|
||||
|
||||
struct Weapon FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
struct Weapon FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef WeaponT NativeTableType;
|
||||
typedef WeaponBuilder Builder;
|
||||
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return WeaponTypeTable();
|
||||
}
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_NAME = 4,
|
||||
VT_DAMAGE = 6
|
||||
};
|
||||
const flatbuffers::String *name() const {
|
||||
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
||||
const ::flatbuffers::String *name() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_NAME);
|
||||
}
|
||||
flatbuffers::String *mutable_name() {
|
||||
return GetPointer<flatbuffers::String *>(VT_NAME);
|
||||
::flatbuffers::String *mutable_name() {
|
||||
return GetPointer<::flatbuffers::String *>(VT_NAME);
|
||||
}
|
||||
int16_t damage() const {
|
||||
return GetField<int16_t>(VT_DAMAGE, 0);
|
||||
@@ -491,42 +491,42 @@ struct Weapon FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
bool mutate_damage(int16_t _damage = 0) {
|
||||
return SetField<int16_t>(VT_DAMAGE, _damage, 0);
|
||||
}
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyOffset(verifier, VT_NAME) &&
|
||||
verifier.VerifyString(name()) &&
|
||||
VerifyField<int16_t>(verifier, VT_DAMAGE, 2) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
WeaponT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
void UnPackTo(WeaponT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
static flatbuffers::Offset<Weapon> Pack(flatbuffers::FlatBufferBuilder &_fbb, const WeaponT* _o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
WeaponT *UnPack(const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
void UnPackTo(WeaponT *_o, const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
static ::flatbuffers::Offset<Weapon> Pack(::flatbuffers::FlatBufferBuilder &_fbb, const WeaponT* _o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
};
|
||||
|
||||
struct WeaponBuilder {
|
||||
typedef Weapon Table;
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_name(::flatbuffers::Offset<::flatbuffers::String> name) {
|
||||
fbb_.AddOffset(Weapon::VT_NAME, name);
|
||||
}
|
||||
void add_damage(int16_t damage) {
|
||||
fbb_.AddElement<int16_t>(Weapon::VT_DAMAGE, damage, 0);
|
||||
}
|
||||
explicit WeaponBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||
explicit WeaponBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
flatbuffers::Offset<Weapon> Finish() {
|
||||
::flatbuffers::Offset<Weapon> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Weapon>(end);
|
||||
auto o = ::flatbuffers::Offset<Weapon>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline flatbuffers::Offset<Weapon> CreateWeapon(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
||||
inline ::flatbuffers::Offset<Weapon> CreateWeapon(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
::flatbuffers::Offset<::flatbuffers::String> name = 0,
|
||||
int16_t damage = 0) {
|
||||
WeaponBuilder builder_(_fbb);
|
||||
builder_.add_name(name);
|
||||
@@ -534,8 +534,8 @@ inline flatbuffers::Offset<Weapon> CreateWeapon(
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<Weapon> CreateWeaponDirect(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
inline ::flatbuffers::Offset<Weapon> CreateWeaponDirect(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const char *name = nullptr,
|
||||
int16_t damage = 0) {
|
||||
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||
@@ -545,7 +545,7 @@ inline flatbuffers::Offset<Weapon> CreateWeaponDirect(
|
||||
damage);
|
||||
}
|
||||
|
||||
flatbuffers::Offset<Weapon> CreateWeapon(flatbuffers::FlatBufferBuilder &_fbb, const WeaponT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
::flatbuffers::Offset<Weapon> CreateWeapon(::flatbuffers::FlatBufferBuilder &_fbb, const WeaponT *_o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
|
||||
|
||||
inline bool operator==(const MonsterT &lhs, const MonsterT &rhs) {
|
||||
@@ -592,13 +592,13 @@ inline MonsterT &MonsterT::operator=(MonsterT o) FLATBUFFERS_NOEXCEPT {
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline MonsterT *Monster::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||
inline MonsterT *Monster::UnPack(const ::flatbuffers::resolver_function_t *_resolver) const {
|
||||
auto _o = std::unique_ptr<MonsterT>(new MonsterT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
return _o.release();
|
||||
}
|
||||
|
||||
inline void Monster::UnPackTo(MonsterT *_o, const flatbuffers::resolver_function_t *_resolver) const {
|
||||
inline void Monster::UnPackTo(MonsterT *_o, const ::flatbuffers::resolver_function_t *_resolver) const {
|
||||
(void)_o;
|
||||
(void)_resolver;
|
||||
{ auto _e = pos(); if (_e) _o->pos = flatbuffers::unique_ptr<MyGame::Sample::Vec3>(new MyGame::Sample::Vec3(*_e)); }
|
||||
@@ -607,27 +607,27 @@ inline void Monster::UnPackTo(MonsterT *_o, const flatbuffers::resolver_function
|
||||
{ auto _e = name(); if (_e) _o->name = _e->str(); }
|
||||
{ auto _e = inventory(); if (_e) { _o->inventory.resize(_e->size()); std::copy(_e->begin(), _e->end(), _o->inventory.begin()); } }
|
||||
{ auto _e = color(); _o->color = _e; }
|
||||
{ auto _e = weapons(); if (_e) { _o->weapons.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { if(_o->weapons[_i]) { _e->Get(_i)->UnPackTo(_o->weapons[_i].get(), _resolver); } else { _o->weapons[_i] = flatbuffers::unique_ptr<MyGame::Sample::WeaponT>(_e->Get(_i)->UnPack(_resolver)); }; } } else { _o->weapons.resize(0); } }
|
||||
{ auto _e = weapons(); if (_e) { _o->weapons.resize(_e->size()); for (::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { if(_o->weapons[_i]) { _e->Get(_i)->UnPackTo(_o->weapons[_i].get(), _resolver); } else { _o->weapons[_i] = flatbuffers::unique_ptr<MyGame::Sample::WeaponT>(_e->Get(_i)->UnPack(_resolver)); }; } } else { _o->weapons.resize(0); } }
|
||||
{ auto _e = equipped_type(); _o->equipped.type = _e; }
|
||||
{ auto _e = equipped(); if (_e) _o->equipped.value = MyGame::Sample::EquipmentUnion::UnPack(_e, equipped_type(), _resolver); }
|
||||
{ auto _e = path(); if (_e) { _o->path.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->path[_i] = *_e->Get(_i); } } else { _o->path.resize(0); } }
|
||||
{ auto _e = path(); if (_e) { _o->path.resize(_e->size()); for (::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->path[_i] = *_e->Get(_i); } } else { _o->path.resize(0); } }
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<Monster> Monster::Pack(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
|
||||
inline ::flatbuffers::Offset<Monster> Monster::Pack(::flatbuffers::FlatBufferBuilder &_fbb, const MonsterT* _o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
return CreateMonster(_fbb, _o, _rehasher);
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT *_o, const flatbuffers::rehasher_function_t *_rehasher) {
|
||||
inline ::flatbuffers::Offset<Monster> CreateMonster(::flatbuffers::FlatBufferBuilder &_fbb, const MonsterT *_o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
(void)_rehasher;
|
||||
(void)_o;
|
||||
struct _VectorArgs { flatbuffers::FlatBufferBuilder *__fbb; const MonsterT* __o; const flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
|
||||
struct _VectorArgs { ::flatbuffers::FlatBufferBuilder *__fbb; const MonsterT* __o; const ::flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
|
||||
auto _pos = _o->pos ? _o->pos.get() : nullptr;
|
||||
auto _mana = _o->mana;
|
||||
auto _hp = _o->hp;
|
||||
auto _name = _o->name.empty() ? 0 : _fbb.CreateString(_o->name);
|
||||
auto _inventory = _o->inventory.size() ? _fbb.CreateVector(_o->inventory) : 0;
|
||||
auto _color = _o->color;
|
||||
auto _weapons = _o->weapons.size() ? _fbb.CreateVector<flatbuffers::Offset<MyGame::Sample::Weapon>> (_o->weapons.size(), [](size_t i, _VectorArgs *__va) { return CreateWeapon(*__va->__fbb, __va->__o->weapons[i].get(), __va->__rehasher); }, &_va ) : 0;
|
||||
auto _weapons = _o->weapons.size() ? _fbb.CreateVector<::flatbuffers::Offset<MyGame::Sample::Weapon>> (_o->weapons.size(), [](size_t i, _VectorArgs *__va) { return CreateWeapon(*__va->__fbb, __va->__o->weapons[i].get(), __va->__rehasher); }, &_va ) : 0;
|
||||
auto _equipped_type = _o->equipped.type;
|
||||
auto _equipped = _o->equipped.Pack(_fbb);
|
||||
auto _path = _o->path.size() ? _fbb.CreateVectorOfStructs(_o->path) : 0;
|
||||
@@ -657,27 +657,27 @@ inline bool operator!=(const WeaponT &lhs, const WeaponT &rhs) {
|
||||
}
|
||||
|
||||
|
||||
inline WeaponT *Weapon::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||
inline WeaponT *Weapon::UnPack(const ::flatbuffers::resolver_function_t *_resolver) const {
|
||||
auto _o = std::unique_ptr<WeaponT>(new WeaponT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
return _o.release();
|
||||
}
|
||||
|
||||
inline void Weapon::UnPackTo(WeaponT *_o, const flatbuffers::resolver_function_t *_resolver) const {
|
||||
inline void Weapon::UnPackTo(WeaponT *_o, const ::flatbuffers::resolver_function_t *_resolver) const {
|
||||
(void)_o;
|
||||
(void)_resolver;
|
||||
{ auto _e = name(); if (_e) _o->name = _e->str(); }
|
||||
{ auto _e = damage(); _o->damage = _e; }
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<Weapon> Weapon::Pack(flatbuffers::FlatBufferBuilder &_fbb, const WeaponT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
|
||||
inline ::flatbuffers::Offset<Weapon> Weapon::Pack(::flatbuffers::FlatBufferBuilder &_fbb, const WeaponT* _o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
return CreateWeapon(_fbb, _o, _rehasher);
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<Weapon> CreateWeapon(flatbuffers::FlatBufferBuilder &_fbb, const WeaponT *_o, const flatbuffers::rehasher_function_t *_rehasher) {
|
||||
inline ::flatbuffers::Offset<Weapon> CreateWeapon(::flatbuffers::FlatBufferBuilder &_fbb, const WeaponT *_o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
(void)_rehasher;
|
||||
(void)_o;
|
||||
struct _VectorArgs { flatbuffers::FlatBufferBuilder *__fbb; const WeaponT* __o; const flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
|
||||
struct _VectorArgs { ::flatbuffers::FlatBufferBuilder *__fbb; const WeaponT* __o; const ::flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
|
||||
auto _name = _o->name.empty() ? 0 : _fbb.CreateString(_o->name);
|
||||
auto _damage = _o->damage;
|
||||
return MyGame::Sample::CreateWeapon(
|
||||
@@ -686,7 +686,7 @@ inline flatbuffers::Offset<Weapon> CreateWeapon(flatbuffers::FlatBufferBuilder &
|
||||
_damage);
|
||||
}
|
||||
|
||||
inline bool VerifyEquipment(flatbuffers::Verifier &verifier, const void *obj, Equipment type) {
|
||||
inline bool VerifyEquipment(::flatbuffers::Verifier &verifier, const void *obj, Equipment type) {
|
||||
switch (type) {
|
||||
case Equipment_NONE: {
|
||||
return true;
|
||||
@@ -699,10 +699,10 @@ inline bool VerifyEquipment(flatbuffers::Verifier &verifier, const void *obj, Eq
|
||||
}
|
||||
}
|
||||
|
||||
inline bool VerifyEquipmentVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types) {
|
||||
inline bool VerifyEquipmentVector(::flatbuffers::Verifier &verifier, const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values, const ::flatbuffers::Vector<uint8_t> *types) {
|
||||
if (!values || !types) return !values && !types;
|
||||
if (values->size() != types->size()) return false;
|
||||
for (flatbuffers::uoffset_t i = 0; i < values->size(); ++i) {
|
||||
for (::flatbuffers::uoffset_t i = 0; i < values->size(); ++i) {
|
||||
if (!VerifyEquipment(
|
||||
verifier, values->Get(i), types->GetEnum<Equipment>(i))) {
|
||||
return false;
|
||||
@@ -711,7 +711,7 @@ inline bool VerifyEquipmentVector(flatbuffers::Verifier &verifier, const flatbuf
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void *EquipmentUnion::UnPack(const void *obj, Equipment type, const flatbuffers::resolver_function_t *resolver) {
|
||||
inline void *EquipmentUnion::UnPack(const void *obj, Equipment type, const ::flatbuffers::resolver_function_t *resolver) {
|
||||
(void)resolver;
|
||||
switch (type) {
|
||||
case Equipment_Weapon: {
|
||||
@@ -722,7 +722,7 @@ inline void *EquipmentUnion::UnPack(const void *obj, Equipment type, const flatb
|
||||
}
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<void> EquipmentUnion::Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher) const {
|
||||
inline ::flatbuffers::Offset<void> EquipmentUnion::Pack(::flatbuffers::FlatBufferBuilder &_fbb, const ::flatbuffers::rehasher_function_t *_rehasher) const {
|
||||
(void)_rehasher;
|
||||
switch (type) {
|
||||
case Equipment_Weapon: {
|
||||
@@ -757,13 +757,13 @@ inline void EquipmentUnion::Reset() {
|
||||
type = Equipment_NONE;
|
||||
}
|
||||
|
||||
inline const flatbuffers::TypeTable *ColorTypeTable() {
|
||||
static const flatbuffers::TypeCode type_codes[] = {
|
||||
{ flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ flatbuffers::ET_CHAR, 0, 0 }
|
||||
inline const ::flatbuffers::TypeTable *ColorTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 }
|
||||
};
|
||||
static const flatbuffers::TypeFunction type_refs[] = {
|
||||
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||
MyGame::Sample::ColorTypeTable
|
||||
};
|
||||
static const char * const names[] = {
|
||||
@@ -771,35 +771,35 @@ inline const flatbuffers::TypeTable *ColorTypeTable() {
|
||||
"Green",
|
||||
"Blue"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_ENUM, 3, type_codes, type_refs, nullptr, nullptr, names
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_ENUM, 3, type_codes, type_refs, nullptr, nullptr, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const flatbuffers::TypeTable *EquipmentTypeTable() {
|
||||
static const flatbuffers::TypeCode type_codes[] = {
|
||||
{ flatbuffers::ET_SEQUENCE, 0, -1 },
|
||||
{ flatbuffers::ET_SEQUENCE, 0, 0 }
|
||||
inline const ::flatbuffers::TypeTable *EquipmentTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, -1 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 0 }
|
||||
};
|
||||
static const flatbuffers::TypeFunction type_refs[] = {
|
||||
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||
MyGame::Sample::WeaponTypeTable
|
||||
};
|
||||
static const char * const names[] = {
|
||||
"NONE",
|
||||
"Weapon"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_UNION, 2, type_codes, type_refs, nullptr, nullptr, names
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_UNION, 2, type_codes, type_refs, nullptr, nullptr, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const flatbuffers::TypeTable *Vec3TypeTable() {
|
||||
static const flatbuffers::TypeCode type_codes[] = {
|
||||
{ flatbuffers::ET_FLOAT, 0, -1 },
|
||||
{ flatbuffers::ET_FLOAT, 0, -1 },
|
||||
{ flatbuffers::ET_FLOAT, 0, -1 }
|
||||
inline const ::flatbuffers::TypeTable *Vec3TypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_FLOAT, 0, -1 },
|
||||
{ ::flatbuffers::ET_FLOAT, 0, -1 },
|
||||
{ ::flatbuffers::ET_FLOAT, 0, -1 }
|
||||
};
|
||||
static const int64_t values[] = { 0, 4, 8, 12 };
|
||||
static const char * const names[] = {
|
||||
@@ -807,27 +807,27 @@ inline const flatbuffers::TypeTable *Vec3TypeTable() {
|
||||
"y",
|
||||
"z"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_STRUCT, 3, type_codes, nullptr, nullptr, values, names
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_STRUCT, 3, type_codes, nullptr, nullptr, values, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const flatbuffers::TypeTable *MonsterTypeTable() {
|
||||
static const flatbuffers::TypeCode type_codes[] = {
|
||||
{ flatbuffers::ET_SEQUENCE, 0, 0 },
|
||||
{ flatbuffers::ET_SHORT, 0, -1 },
|
||||
{ flatbuffers::ET_SHORT, 0, -1 },
|
||||
{ flatbuffers::ET_STRING, 0, -1 },
|
||||
{ flatbuffers::ET_BOOL, 0, -1 },
|
||||
{ flatbuffers::ET_UCHAR, 1, -1 },
|
||||
{ flatbuffers::ET_CHAR, 0, 1 },
|
||||
{ flatbuffers::ET_SEQUENCE, 1, 2 },
|
||||
{ flatbuffers::ET_UTYPE, 0, 3 },
|
||||
{ flatbuffers::ET_SEQUENCE, 0, 3 },
|
||||
{ flatbuffers::ET_SEQUENCE, 1, 0 }
|
||||
inline const ::flatbuffers::TypeTable *MonsterTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 0 },
|
||||
{ ::flatbuffers::ET_SHORT, 0, -1 },
|
||||
{ ::flatbuffers::ET_SHORT, 0, -1 },
|
||||
{ ::flatbuffers::ET_STRING, 0, -1 },
|
||||
{ ::flatbuffers::ET_BOOL, 0, -1 },
|
||||
{ ::flatbuffers::ET_UCHAR, 1, -1 },
|
||||
{ ::flatbuffers::ET_CHAR, 0, 1 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 1, 2 },
|
||||
{ ::flatbuffers::ET_UTYPE, 0, 3 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 3 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 1, 0 }
|
||||
};
|
||||
static const flatbuffers::TypeFunction type_refs[] = {
|
||||
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||
MyGame::Sample::Vec3TypeTable,
|
||||
MyGame::Sample::ColorTypeTable,
|
||||
MyGame::Sample::WeaponTypeTable,
|
||||
@@ -846,74 +846,74 @@ inline const flatbuffers::TypeTable *MonsterTypeTable() {
|
||||
"equipped",
|
||||
"path"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_TABLE, 11, type_codes, type_refs, nullptr, nullptr, names
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_TABLE, 11, type_codes, type_refs, nullptr, nullptr, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const flatbuffers::TypeTable *WeaponTypeTable() {
|
||||
static const flatbuffers::TypeCode type_codes[] = {
|
||||
{ flatbuffers::ET_STRING, 0, -1 },
|
||||
{ flatbuffers::ET_SHORT, 0, -1 }
|
||||
inline const ::flatbuffers::TypeTable *WeaponTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_STRING, 0, -1 },
|
||||
{ ::flatbuffers::ET_SHORT, 0, -1 }
|
||||
};
|
||||
static const char * const names[] = {
|
||||
"name",
|
||||
"damage"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_TABLE, 2, type_codes, nullptr, nullptr, nullptr, names
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_TABLE, 2, type_codes, nullptr, nullptr, nullptr, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const MyGame::Sample::Monster *GetMonster(const void *buf) {
|
||||
return flatbuffers::GetRoot<MyGame::Sample::Monster>(buf);
|
||||
return ::flatbuffers::GetRoot<MyGame::Sample::Monster>(buf);
|
||||
}
|
||||
|
||||
inline const MyGame::Sample::Monster *GetSizePrefixedMonster(const void *buf) {
|
||||
return flatbuffers::GetSizePrefixedRoot<MyGame::Sample::Monster>(buf);
|
||||
return ::flatbuffers::GetSizePrefixedRoot<MyGame::Sample::Monster>(buf);
|
||||
}
|
||||
|
||||
inline Monster *GetMutableMonster(void *buf) {
|
||||
return flatbuffers::GetMutableRoot<Monster>(buf);
|
||||
return ::flatbuffers::GetMutableRoot<Monster>(buf);
|
||||
}
|
||||
|
||||
inline MyGame::Sample::Monster *GetMutableSizePrefixedMonster(void *buf) {
|
||||
return flatbuffers::GetMutableSizePrefixedRoot<MyGame::Sample::Monster>(buf);
|
||||
return ::flatbuffers::GetMutableSizePrefixedRoot<MyGame::Sample::Monster>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyMonsterBuffer(
|
||||
flatbuffers::Verifier &verifier) {
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<MyGame::Sample::Monster>(nullptr);
|
||||
}
|
||||
|
||||
inline bool VerifySizePrefixedMonsterBuffer(
|
||||
flatbuffers::Verifier &verifier) {
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<MyGame::Sample::Monster>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishMonsterBuffer(
|
||||
flatbuffers::FlatBufferBuilder &fbb,
|
||||
flatbuffers::Offset<MyGame::Sample::Monster> root) {
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<MyGame::Sample::Monster> root) {
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void FinishSizePrefixedMonsterBuffer(
|
||||
flatbuffers::FlatBufferBuilder &fbb,
|
||||
flatbuffers::Offset<MyGame::Sample::Monster> root) {
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<MyGame::Sample::Monster> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
inline flatbuffers::unique_ptr<MyGame::Sample::MonsterT> UnPackMonster(
|
||||
const void *buf,
|
||||
const flatbuffers::resolver_function_t *res = nullptr) {
|
||||
const ::flatbuffers::resolver_function_t *res = nullptr) {
|
||||
return flatbuffers::unique_ptr<MyGame::Sample::MonsterT>(GetMonster(buf)->UnPack(res));
|
||||
}
|
||||
|
||||
inline flatbuffers::unique_ptr<MyGame::Sample::MonsterT> UnPackSizePrefixedMonster(
|
||||
const void *buf,
|
||||
const flatbuffers::resolver_function_t *res = nullptr) {
|
||||
const ::flatbuffers::resolver_function_t *res = nullptr) {
|
||||
return flatbuffers::unique_ptr<MyGame::Sample::MonsterT>(GetSizePrefixedMonster(buf)->UnPack(res));
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import FlatBuffers
|
||||
|
||||
public enum MyGame_Sample_Color: Int8, Enum {
|
||||
public enum MyGame_Sample_Color: Int8, Enum, Verifiable {
|
||||
public typealias T = Int8
|
||||
public static var byteSize: Int { return MemoryLayout<Int8>.size }
|
||||
public var value: Int8 { return self.rawValue }
|
||||
@@ -12,31 +12,43 @@ public enum MyGame_Sample_Color: Int8, Enum {
|
||||
case green = 1
|
||||
case blue = 2
|
||||
|
||||
|
||||
public static var max: MyGame_Sample_Color { return .blue }
|
||||
public static var min: MyGame_Sample_Color { return .red }
|
||||
}
|
||||
|
||||
public enum MyGame_Sample_Equipment: UInt8, Enum {
|
||||
|
||||
public enum MyGame_Sample_Equipment: UInt8, UnionEnum {
|
||||
public typealias T = UInt8
|
||||
|
||||
public init?(value: T) {
|
||||
self.init(rawValue: value)
|
||||
}
|
||||
|
||||
public static var byteSize: Int { return MemoryLayout<UInt8>.size }
|
||||
public var value: UInt8 { return self.rawValue }
|
||||
case none_ = 0
|
||||
case weapon = 1
|
||||
|
||||
|
||||
public static var max: MyGame_Sample_Equipment { return .weapon }
|
||||
public static var min: MyGame_Sample_Equipment { return .none_ }
|
||||
}
|
||||
|
||||
public struct MyGame_Sample_Vec3: NativeStruct {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
||||
public struct MyGame_Sample_Vec3: NativeStruct, Verifiable, FlatbuffersInitializable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_1_21() }
|
||||
|
||||
private var _x: Float32
|
||||
private var _y: Float32
|
||||
private var _z: Float32
|
||||
|
||||
public init(_ bb: ByteBuffer, o: Int32) {
|
||||
let _accessor = Struct(bb: bb, position: o)
|
||||
_x = _accessor.readBuffer(of: Float32.self, at: 0)
|
||||
_y = _accessor.readBuffer(of: Float32.self, at: 4)
|
||||
_z = _accessor.readBuffer(of: Float32.self, at: 8)
|
||||
}
|
||||
|
||||
public init(x: Float32, y: Float32, z: Float32) {
|
||||
_x = x
|
||||
_y = y
|
||||
@@ -52,11 +64,15 @@ public struct MyGame_Sample_Vec3: NativeStruct {
|
||||
public var x: Float32 { _x }
|
||||
public var y: Float32 { _y }
|
||||
public var z: Float32 { _z }
|
||||
|
||||
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
|
||||
try verifier.inBuffer(position: position, of: MyGame_Sample_Vec3.self)
|
||||
}
|
||||
}
|
||||
|
||||
public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
||||
static func validateVersion() { FlatBuffersVersion_23_1_21() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Struct
|
||||
|
||||
@@ -70,14 +86,12 @@ public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
|
||||
@discardableResult public func mutate(z: Float32) -> Bool { return _accessor.mutate(z, index: 8) }
|
||||
}
|
||||
|
||||
public struct MyGame_Sample_Monster: FlatBufferObject {
|
||||
public struct MyGame_Sample_Monster: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
||||
static func validateVersion() { FlatBuffersVersion_23_1_21() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
public static func getRootAsMonster(bb: ByteBuffer) -> MyGame_Sample_Monster { return MyGame_Sample_Monster(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
||||
|
||||
private init(_ t: Table) { _accessor = t }
|
||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||
|
||||
@@ -104,16 +118,19 @@ public struct MyGame_Sample_Monster: FlatBufferObject {
|
||||
@discardableResult public func mutate(hp: Int16) -> Bool {let o = _accessor.offset(VTOFFSET.hp.v); return _accessor.mutate(hp, index: o) }
|
||||
public var name: String? { let o = _accessor.offset(VTOFFSET.name.v); return o == 0 ? nil : _accessor.string(at: o) }
|
||||
public var nameSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.name.v) }
|
||||
public var hasInventory: Bool { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? false : true }
|
||||
public var inventoryCount: Int32 { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? 0 : _accessor.vector(count: o) }
|
||||
public func inventory(at index: Int32) -> UInt8 { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? 0 : _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1) }
|
||||
public var inventory: [UInt8] { return _accessor.getVector(at: VTOFFSET.inventory.v) ?? [] }
|
||||
public func mutate(inventory: UInt8, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.inventory.v); return _accessor.directMutate(inventory, index: _accessor.vector(at: o) + index * 1) }
|
||||
public var color: MyGame_Sample_Color { let o = _accessor.offset(VTOFFSET.color.v); return o == 0 ? .blue : MyGame_Sample_Color(rawValue: _accessor.readBuffer(of: Int8.self, at: o)) ?? .blue }
|
||||
@discardableResult public func mutate(color: MyGame_Sample_Color) -> Bool {let o = _accessor.offset(VTOFFSET.color.v); return _accessor.mutate(color.rawValue, index: o) }
|
||||
public var hasWeapons: Bool { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? false : true }
|
||||
public var weaponsCount: Int32 { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? 0 : _accessor.vector(count: o) }
|
||||
public func weapons(at index: Int32) -> MyGame_Sample_Weapon? { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? nil : MyGame_Sample_Weapon(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
|
||||
public var equippedType: MyGame_Sample_Equipment { let o = _accessor.offset(VTOFFSET.equippedType.v); return o == 0 ? .none_ : MyGame_Sample_Equipment(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .none_ }
|
||||
public func equipped<T: FlatbuffersInitializable>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.equipped.v); return o == 0 ? nil : _accessor.union(o) }
|
||||
public var hasPath: Bool { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? false : true }
|
||||
public var pathCount: Int32 { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? 0 : _accessor.vector(count: o) }
|
||||
public func path(at index: Int32) -> MyGame_Sample_Vec3? { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? nil : _accessor.directRead(of: MyGame_Sample_Vec3.self, offset: _accessor.vector(at: o) + index * 12) }
|
||||
public func mutablePath(at index: Int32) -> MyGame_Sample_Vec3_Mutable? { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? nil : MyGame_Sample_Vec3_Mutable(_accessor.bb, o: _accessor.vector(at: o) + index * 12) }
|
||||
@@ -158,16 +175,35 @@ public struct MyGame_Sample_Monster: FlatBufferObject {
|
||||
MyGame_Sample_Monster.addVectorOf(path: path, &fbb)
|
||||
return MyGame_Sample_Monster.endMonster(&fbb, start: __start)
|
||||
}
|
||||
|
||||
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
|
||||
var _v = try verifier.visitTable(at: position)
|
||||
try _v.visit(field: VTOFFSET.pos.p, fieldName: "pos", required: false, type: MyGame_Sample_Vec3.self)
|
||||
try _v.visit(field: VTOFFSET.mana.p, fieldName: "mana", required: false, type: Int16.self)
|
||||
try _v.visit(field: VTOFFSET.hp.p, fieldName: "hp", required: false, type: Int16.self)
|
||||
try _v.visit(field: VTOFFSET.name.p, fieldName: "name", required: false, type: ForwardOffset<String>.self)
|
||||
try _v.visit(field: VTOFFSET.inventory.p, fieldName: "inventory", required: false, type: ForwardOffset<Vector<UInt8, UInt8>>.self)
|
||||
try _v.visit(field: VTOFFSET.color.p, fieldName: "color", required: false, type: MyGame_Sample_Color.self)
|
||||
try _v.visit(field: VTOFFSET.weapons.p, fieldName: "weapons", required: false, type: ForwardOffset<Vector<ForwardOffset<MyGame_Sample_Weapon>, MyGame_Sample_Weapon>>.self)
|
||||
try _v.visit(unionKey: VTOFFSET.equippedType.p, unionField: VTOFFSET.equipped.p, unionKeyName: "equippedType", fieldName: "equipped", required: false, completion: { (verifier, key: MyGame_Sample_Equipment, pos) in
|
||||
switch key {
|
||||
case .none_:
|
||||
break // NOTE - SWIFT doesnt support none
|
||||
case .weapon:
|
||||
try ForwardOffset<MyGame_Sample_Weapon>.verify(&verifier, at: pos, of: MyGame_Sample_Weapon.self)
|
||||
}
|
||||
})
|
||||
try _v.visit(field: VTOFFSET.path.p, fieldName: "path", required: false, type: ForwardOffset<Vector<MyGame_Sample_Vec3, MyGame_Sample_Vec3>>.self)
|
||||
_v.finish()
|
||||
}
|
||||
}
|
||||
|
||||
public struct MyGame_Sample_Weapon: FlatBufferObject {
|
||||
public struct MyGame_Sample_Weapon: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
||||
static func validateVersion() { FlatBuffersVersion_23_1_21() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
public static func getRootAsWeapon(bb: ByteBuffer) -> MyGame_Sample_Weapon { return MyGame_Sample_Weapon(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
||||
|
||||
private init(_ t: Table) { _accessor = t }
|
||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||
|
||||
@@ -196,5 +232,12 @@ public struct MyGame_Sample_Weapon: FlatBufferObject {
|
||||
MyGame_Sample_Weapon.add(damage: damage, &fbb)
|
||||
return MyGame_Sample_Weapon.endWeapon(&fbb, start: __start)
|
||||
}
|
||||
|
||||
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
|
||||
var _v = try verifier.visitTable(at: position)
|
||||
try _v.visit(field: VTOFFSET.name.p, fieldName: "name", required: false, type: ForwardOffset<String>.self)
|
||||
try _v.visit(field: VTOFFSET.damage.p, fieldName: "damage", required: false, type: Int16.self)
|
||||
_v.finish()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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.
|
||||
@@ -56,8 +56,8 @@ func main() {
|
||||
equippedOffset: axe)
|
||||
builder.finish(offset: orc)
|
||||
|
||||
let buf = builder.sizedByteArray
|
||||
let monster = Monster.getRootAsMonster(bb: ByteBuffer(bytes: buf))
|
||||
var buf = ByteBuffer(bytes: builder.sizedByteArray)
|
||||
let monster: Monster = try! getCheckedRoot(byteBuffer: &buffer)
|
||||
|
||||
assert(monster.mana == 150)
|
||||
assert(monster.hp == 300)
|
||||
|
||||
@@ -29,7 +29,7 @@ root_path = script_path.parent.absolute()
|
||||
print("Generating GRPC code...")
|
||||
generate_grpc_examples.GenerateGRPCExamples()
|
||||
|
||||
result = subprocess.run(["git", "diff", "--quiet"], cwd=root_path)
|
||||
result = subprocess.run(["git", "diff", "--quiet", "--ignore-cr-at-eol"], cwd=root_path)
|
||||
|
||||
if result.returncode != 0:
|
||||
print(
|
||||
|
||||
@@ -26,7 +26,7 @@ script_path = Path(__file__).parent.resolve()
|
||||
# Get the root path as an absolute path, so all derived paths are absolute.
|
||||
root_path = script_path.parent.absolute()
|
||||
|
||||
result = subprocess.run(["git", "diff", "--quiet"], cwd=root_path)
|
||||
result = subprocess.run(["git", "diff", "--quiet", "--ignore-cr-at-eol"], cwd=root_path)
|
||||
|
||||
if result.returncode != 0:
|
||||
print(
|
||||
@@ -46,7 +46,7 @@ if platform.system() == "Windows":
|
||||
gen_cmd = ["py"] + gen_cmd
|
||||
subprocess.run(gen_cmd, cwd=root_path)
|
||||
|
||||
result = subprocess.run(["git", "diff", "--quiet"], cwd=root_path)
|
||||
result = subprocess.run(["git", "diff", "--quiet", "--ignore-cr-at-eol"], cwd=root_path)
|
||||
|
||||
if result.returncode != 0:
|
||||
print(
|
||||
|
||||
@@ -14,73 +14,20 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import argparse
|
||||
import filecmp
|
||||
import glob
|
||||
import platform
|
||||
import shutil
|
||||
import subprocess
|
||||
import generate_grpc_examples
|
||||
from pathlib import Path
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--flatc",
|
||||
help="path of the Flat C compiler relative to the root directory",
|
||||
)
|
||||
parser.add_argument("--cpp-0x", action="store_true", help="use --cpp-std c++ox")
|
||||
parser.add_argument(
|
||||
"--skip-monster-extra",
|
||||
action="store_true",
|
||||
help="skip generating tests involving monster_extra.fbs",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--skip-gen-reflection",
|
||||
action="store_true",
|
||||
help="skip generating the reflection.fbs files",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
# Get the path where this script is located so we can invoke the script from
|
||||
# any directory and have the paths work correctly.
|
||||
script_path = Path(__file__).parent.resolve()
|
||||
|
||||
# Get the root path as an absolute path, so all derived paths are absolute.
|
||||
root_path = script_path.parent.absolute()
|
||||
|
||||
# Get the location of the flatc executable, reading from the first command line
|
||||
# argument or defaulting to default names.
|
||||
flatc_exe = Path(
|
||||
("flatc" if not platform.system() == "Windows" else "flatc.exe")
|
||||
if not args.flatc
|
||||
else args.flatc
|
||||
)
|
||||
|
||||
# Find and assert flatc compiler is present.
|
||||
if root_path in flatc_exe.parents:
|
||||
flatc_exe = flatc_exe.relative_to(root_path)
|
||||
flatc_path = Path(root_path, flatc_exe)
|
||||
assert flatc_path.exists(), "Cannot find the flatc compiler " + str(flatc_path)
|
||||
from util import flatc, root_path, tests_path, args, flatc_path
|
||||
|
||||
# Specify the other paths that will be referenced
|
||||
tests_path = Path(root_path, "tests")
|
||||
swift_code_gen = Path(root_path, "tests/swift/tests/CodeGenerationTests")
|
||||
ts_code_gen = Path(root_path, "tests/ts")
|
||||
samples_path = Path(root_path, "samples")
|
||||
reflection_path = Path(root_path, "reflection")
|
||||
|
||||
# Execute the flatc compiler with the specified parameters
|
||||
def flatc(options, schema, prefix=None, include=None, data=None, cwd=tests_path):
|
||||
cmd = [str(flatc_path)] + options
|
||||
if prefix:
|
||||
cmd += ["-o"] + [prefix]
|
||||
if include:
|
||||
cmd += ["-I"] + [include]
|
||||
cmd += [schema] if isinstance(schema, str) else schema
|
||||
if data:
|
||||
cmd += [data] if isinstance(data, str) else data
|
||||
result = subprocess.run(cmd, cwd=str(cwd), check=True)
|
||||
|
||||
|
||||
# Generate the code for flatbuffers reflection schema
|
||||
def flatc_reflection(options, location, target):
|
||||
full_options = ["--no-prefix"] + options
|
||||
@@ -150,7 +97,7 @@ SWIFT_OPTS_CODE_GEN = [
|
||||
"--swift",
|
||||
"--gen-json-emit",
|
||||
"--bfbs-filenames",
|
||||
swift_code_gen
|
||||
str(swift_code_gen)
|
||||
]
|
||||
JAVA_OPTS = ["--java"]
|
||||
KOTLIN_OPTS = ["--kotlin"]
|
||||
@@ -196,10 +143,10 @@ flatc(
|
||||
flatc(
|
||||
NO_INCL_OPTS
|
||||
+ TS_OPTS,
|
||||
schema="monster_test.fbs",
|
||||
prefix="ts",
|
||||
include="include_test",
|
||||
data="monsterdata_test.json",
|
||||
cwd=ts_code_gen,
|
||||
schema="../monster_test.fbs",
|
||||
include="../include_test",
|
||||
data="../monsterdata_test.json",
|
||||
)
|
||||
|
||||
flatc(
|
||||
@@ -264,37 +211,31 @@ flatc(
|
||||
|
||||
flatc(
|
||||
BASE_OPTS + TS_OPTS,
|
||||
prefix="ts/union_vector",
|
||||
schema="union_vector/union_vector.fbs",
|
||||
cwd=ts_code_gen,
|
||||
prefix="union_vector",
|
||||
schema="../union_vector/union_vector.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
BASE_OPTS + TS_OPTS + ["--gen-name-strings", "--gen-mutable"],
|
||||
include="include_test",
|
||||
prefix="ts",
|
||||
schema="monster_test.fbs",
|
||||
)
|
||||
|
||||
# Generate the complete flat file TS of monster.
|
||||
flatc(
|
||||
["--ts", "--gen-all", "--ts-flat-files"],
|
||||
include="include_test",
|
||||
schema="monster_test.fbs",
|
||||
prefix="ts/ts-flat-files"
|
||||
cwd=ts_code_gen,
|
||||
include="../include_test",
|
||||
schema="../monster_test.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
BASE_OPTS + TS_OPTS + ["-b"],
|
||||
include="include_test",
|
||||
prefix="ts",
|
||||
schema="monster_test.fbs",
|
||||
data="unicode_test.json",
|
||||
cwd=ts_code_gen,
|
||||
include="../include_test",
|
||||
schema="../monster_test.fbs",
|
||||
data="../unicode_test.json",
|
||||
)
|
||||
|
||||
flatc(
|
||||
BASE_OPTS + TS_OPTS + ["--gen-name-strings"],
|
||||
prefix="ts/union_vector",
|
||||
schema="union_vector/union_vector.fbs",
|
||||
cwd=ts_code_gen,
|
||||
prefix="union_vector",
|
||||
schema="../union_vector/union_vector.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
@@ -394,7 +335,7 @@ flatc(
|
||||
# Optional Scalars
|
||||
optional_scalars_schema = "optional_scalars.fbs"
|
||||
flatc(["--java", "--kotlin", "--lobster"], schema=optional_scalars_schema)
|
||||
flatc(TS_OPTS, schema=optional_scalars_schema, prefix="ts")
|
||||
flatc(TS_OPTS, cwd=ts_code_gen, schema="../optional_scalars.fbs")
|
||||
|
||||
flatc(["--csharp", "--python", "--gen-object-api"], schema=optional_scalars_schema)
|
||||
|
||||
@@ -407,6 +348,13 @@ type_field_collsion_schema = "type_field_collsion.fbs"
|
||||
|
||||
flatc(["--csharp", "--gen-object-api"], schema=type_field_collsion_schema)
|
||||
|
||||
# Union / value collision
|
||||
flatc(
|
||||
CS_OPTS + ["--gen-object-api", "--gen-onefile"],
|
||||
prefix="union_value_collsion",
|
||||
schema="union_value_collision.fbs"
|
||||
)
|
||||
|
||||
# Generate string/vector default code for tests
|
||||
flatc(RUST_OPTS, prefix="more_defaults", schema="more_defaults.fbs")
|
||||
|
||||
@@ -470,6 +418,15 @@ flatc(
|
||||
cwd=swift_code_gen
|
||||
)
|
||||
|
||||
# Swift Wasm Tests
|
||||
swift_Wasm_prefix = "swift/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests"
|
||||
flatc(
|
||||
SWIFT_OPTS + BASE_OPTS,
|
||||
schema="monster_test.fbs",
|
||||
include="include_test",
|
||||
prefix=swift_Wasm_prefix,
|
||||
)
|
||||
|
||||
# Nim Tests
|
||||
NIM_OPTS = BASE_OPTS + ["--nim"]
|
||||
flatc(NIM_OPTS, schema="monster_test.fbs", include="include_test")
|
||||
|
||||
@@ -19,7 +19,7 @@ from pathlib import Path
|
||||
|
||||
grpc_examples_path = Path(root_path, "grpc/examples")
|
||||
|
||||
greeter_schema = Path(grpc_examples_path, "greeter.fbs")
|
||||
greeter_schema = str(Path(grpc_examples_path, "greeter.fbs"))
|
||||
|
||||
COMMON_ARGS = [
|
||||
"--grpc",
|
||||
|
||||
@@ -12,20 +12,44 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import argparse
|
||||
import platform
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--flatc",
|
||||
help="path of the Flat C compiler relative to the root directory",
|
||||
)
|
||||
parser.add_argument("--cpp-0x", action="store_true", help="use --cpp-std c++ox")
|
||||
parser.add_argument(
|
||||
"--skip-monster-extra",
|
||||
action="store_true",
|
||||
help="skip generating tests involving monster_extra.fbs",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--skip-gen-reflection",
|
||||
action="store_true",
|
||||
help="skip generating the reflection.fbs files",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
# Get the path where this script is located so we can invoke the script from
|
||||
# any directory and have the paths work correctly.
|
||||
script_path = Path(__file__).parent.resolve()
|
||||
|
||||
# Get the root path as an absolute path, so all derived paths are absolute.
|
||||
root_path = script_path.parent.absolute()
|
||||
tests_path = Path(root_path, "tests")
|
||||
|
||||
# Get the location of the flatc executable, reading from the first command line
|
||||
# argument or defaulting to default names.
|
||||
flatc_exe = Path("flatc" if not platform.system() == "Windows" else "flatc.exe")
|
||||
flatc_exe = Path(
|
||||
("flatc" if not platform.system() == "Windows" else "flatc.exe")
|
||||
if not args.flatc
|
||||
else args.flatc
|
||||
)
|
||||
|
||||
# Find and assert flatc compiler is present.
|
||||
if root_path in flatc_exe.parents:
|
||||
@@ -34,18 +58,13 @@ flatc_path = Path(root_path, flatc_exe)
|
||||
assert flatc_path.exists(), "Cannot find the flatc compiler " + str(flatc_path)
|
||||
|
||||
# Execute the flatc compiler with the specified parameters
|
||||
def flatc(options, schema, prefix=None, include=None, data=None, cwd=root_path):
|
||||
def flatc(options, schema, prefix=None, include=None, data=None, cwd=tests_path):
|
||||
cmd = [str(flatc_path)] + options
|
||||
if prefix:
|
||||
cmd += ["-o"] + [prefix]
|
||||
if include:
|
||||
cmd += ["-I"] + [include]
|
||||
if isinstance(schema, Path):
|
||||
cmd += [str(schema)]
|
||||
elif isinstance(schema, str):
|
||||
cmd += [schema]
|
||||
else:
|
||||
cmd += schema
|
||||
cmd += [schema] if isinstance(schema, str) else schema
|
||||
if data:
|
||||
cmd += [data] if isinstance(data, str) else data
|
||||
return subprocess.check_call(cmd, cwd=str(cwd))
|
||||
result = subprocess.run(cmd, cwd=str(cwd), check=True)
|
||||
|
||||
@@ -278,7 +278,7 @@ static std::string GenerateDocumentation(const BinaryRegion ®ion,
|
||||
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << std::setw(output_config.largest_type_string) << std::left;
|
||||
ss << std::setw(static_cast<int>(output_config.largest_type_string)) << std::left;
|
||||
ss << GenerateTypeString(region);
|
||||
s += ss.str();
|
||||
}
|
||||
@@ -293,7 +293,7 @@ static std::string GenerateDocumentation(const BinaryRegion ®ion,
|
||||
const std::string value = ToValueString(region, binary, output_config);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << std::setw(output_config.largest_value_string) << std::left;
|
||||
ss << std::setw(static_cast<int>(output_config.largest_value_string)) << std::left;
|
||||
ss << value.substr(0, output_config.max_bytes_per_line);
|
||||
s += ss.str();
|
||||
|
||||
@@ -301,7 +301,7 @@ static std::string GenerateDocumentation(const BinaryRegion ®ion,
|
||||
value.substr(std::min(output_config.max_bytes_per_line, value.size()));
|
||||
} else {
|
||||
std::stringstream ss;
|
||||
ss << std::setw(output_config.largest_value_string) << std::left;
|
||||
ss << std::setw(static_cast<int>(output_config.largest_value_string)) << std::left;
|
||||
ss << ToValueString(region, binary, output_config);
|
||||
s += ss.str();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "flatbuffers/reflection.h"
|
||||
#include "flatbuffers/util.h"
|
||||
#include "flatbuffers/verifier.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
@@ -679,7 +680,8 @@ void BinaryAnnotator::BuildTable(const uint64_t table_offset,
|
||||
|
||||
if (next_object->is_struct()) {
|
||||
// Structs are stored inline.
|
||||
BuildStruct(field_offset, regions, next_object);
|
||||
BuildStruct(field_offset, regions, field->name()->c_str(),
|
||||
next_object);
|
||||
} else {
|
||||
offset_field_comment.default_value = "(table)";
|
||||
|
||||
@@ -780,6 +782,7 @@ void BinaryAnnotator::BuildTable(const uint64_t table_offset,
|
||||
|
||||
uint64_t BinaryAnnotator::BuildStruct(const uint64_t struct_offset,
|
||||
std::vector<BinaryRegion> ®ions,
|
||||
const std::string referring_field_name,
|
||||
const reflection::Object *const object) {
|
||||
if (!object->is_struct()) { return struct_offset; }
|
||||
uint64_t offset = struct_offset;
|
||||
@@ -794,9 +797,8 @@ uint64_t BinaryAnnotator::BuildStruct(const uint64_t struct_offset,
|
||||
|
||||
BinaryRegionComment comment;
|
||||
comment.type = BinaryRegionCommentType::StructField;
|
||||
comment.name =
|
||||
std::string(object->name()->c_str()) + "." + field->name()->c_str();
|
||||
comment.default_value = "(" +
|
||||
comment.name = referring_field_name + "." + field->name()->str();
|
||||
comment.default_value = "of '" + object->name()->str() + "' (" +
|
||||
std::string(reflection::EnumNameBaseType(
|
||||
field->type()->base_type())) +
|
||||
")";
|
||||
@@ -821,6 +823,7 @@ uint64_t BinaryAnnotator::BuildStruct(const uint64_t struct_offset,
|
||||
} else if (field->type()->base_type() == reflection::BaseType::Obj) {
|
||||
// Structs are stored inline, even when nested.
|
||||
offset = BuildStruct(offset, regions,
|
||||
referring_field_name + "." + field->name()->str(),
|
||||
schema_->objects()->Get(field->type()->index()));
|
||||
} else if (field->type()->base_type() == reflection::BaseType::Array) {
|
||||
const bool is_scalar = IsScalar(field->type()->element());
|
||||
@@ -833,11 +836,11 @@ uint64_t BinaryAnnotator::BuildStruct(const uint64_t struct_offset,
|
||||
if (is_scalar) {
|
||||
BinaryRegionComment array_comment;
|
||||
array_comment.type = BinaryRegionCommentType::ArrayField;
|
||||
array_comment.name = std::string(object->name()->c_str()) + "." +
|
||||
field->name()->c_str();
|
||||
array_comment.name =
|
||||
referring_field_name + "." + field->name()->str();
|
||||
array_comment.index = i;
|
||||
array_comment.default_value =
|
||||
"(" +
|
||||
"of '" + object->name()->str() + "' (" +
|
||||
std::string(
|
||||
reflection::EnumNameBaseType(field->type()->element())) +
|
||||
")";
|
||||
@@ -869,8 +872,10 @@ uint64_t BinaryAnnotator::BuildStruct(const uint64_t struct_offset,
|
||||
// TODO(dbaileychess): This works, but the comments on the fields lose
|
||||
// some context. Need to figure a way how to plumb the nested arrays
|
||||
// comments together that isn't too confusing.
|
||||
offset = BuildStruct(offset, regions,
|
||||
schema_->objects()->Get(field->type()->index()));
|
||||
offset =
|
||||
BuildStruct(offset, regions,
|
||||
referring_field_name + "." + field->name()->str(),
|
||||
schema_->objects()->Get(field->type()->index()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1018,7 +1023,8 @@ void BinaryAnnotator::BuildVector(const uint64_t vector_offset,
|
||||
// Vector of structs
|
||||
for (size_t i = 0; i < vector_length.value(); ++i) {
|
||||
// Structs are inline to the vector.
|
||||
const uint64_t next_offset = BuildStruct(offset, regions, object);
|
||||
const uint64_t next_offset =
|
||||
BuildStruct(offset, regions, "[" + NumToString(i) + "]", object);
|
||||
if (next_offset == offset) { break; }
|
||||
offset = next_offset;
|
||||
}
|
||||
@@ -1301,7 +1307,7 @@ std::string BinaryAnnotator::BuildUnion(const uint64_t union_offset,
|
||||
// Union of vectors point to a new Binary section
|
||||
std::vector<BinaryRegion> regions;
|
||||
|
||||
BuildStruct(union_offset, regions, object);
|
||||
BuildStruct(union_offset, regions, field->name()->c_str(), object);
|
||||
|
||||
AddSection(
|
||||
union_offset,
|
||||
|
||||
@@ -52,14 +52,14 @@ enum class BinaryRegionType {
|
||||
template<typename T>
|
||||
static inline std::string ToHex(T i, size_t width = sizeof(T)) {
|
||||
std::stringstream stream;
|
||||
stream << std::hex << std::uppercase << std::setfill('0') << std::setw(width)
|
||||
stream << std::hex << std::uppercase << std::setfill('0') << std::setw(static_cast<int>(width))
|
||||
<< i;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
// Specialized version for uint8_t that don't work well with std::hex.
|
||||
static inline std::string ToHex(uint8_t i) {
|
||||
return ToHex(static_cast<int>(i), 2);
|
||||
return ToHex<int>(static_cast<int>(i), 2);
|
||||
}
|
||||
|
||||
enum class BinaryRegionStatus {
|
||||
@@ -273,6 +273,7 @@ class BinaryAnnotator {
|
||||
const reflection::Object *table);
|
||||
|
||||
uint64_t BuildStruct(uint64_t offset, std::vector<BinaryRegion> ®ions,
|
||||
const std::string referring_field_name,
|
||||
const reflection::Object *structure);
|
||||
|
||||
void BuildString(uint64_t offset, const reflection::Object *table,
|
||||
|
||||
425
src/flatc.cpp
425
src/flatc.cpp
@@ -19,10 +19,13 @@
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
#include "annotated_binary_text_gen.h"
|
||||
#include "binary_annotator.h"
|
||||
#include "flatbuffers/code_generator.h"
|
||||
#include "flatbuffers/idl.h"
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
@@ -32,17 +35,19 @@ static const char *FLATC_VERSION() { return FLATBUFFERS_VERSION(); }
|
||||
void FlatCompiler::ParseFile(
|
||||
flatbuffers::Parser &parser, const std::string &filename,
|
||||
const std::string &contents,
|
||||
std::vector<const char *> &include_directories) const {
|
||||
const std::vector<const char *> &include_directories) const {
|
||||
auto local_include_directory = flatbuffers::StripFileName(filename);
|
||||
include_directories.push_back(local_include_directory.c_str());
|
||||
include_directories.push_back(nullptr);
|
||||
if (!parser.Parse(contents.c_str(), &include_directories[0],
|
||||
filename.c_str())) {
|
||||
|
||||
std::vector<const char *> inc_directories;
|
||||
inc_directories.insert(inc_directories.end(), include_directories.begin(),
|
||||
include_directories.end());
|
||||
inc_directories.push_back(local_include_directory.c_str());
|
||||
inc_directories.push_back(nullptr);
|
||||
|
||||
if (!parser.Parse(contents.c_str(), &inc_directories[0], filename.c_str())) {
|
||||
Error(parser.error_, false, false);
|
||||
}
|
||||
if (!parser.error_.empty()) { Warn(parser.error_, false); }
|
||||
include_directories.pop_back();
|
||||
include_directories.pop_back();
|
||||
}
|
||||
|
||||
void FlatCompiler::LoadBinarySchema(flatbuffers::Parser &parser,
|
||||
@@ -63,7 +68,7 @@ void FlatCompiler::Error(const std::string &err, bool usage,
|
||||
params_.error_fn(this, err, usage, show_exe_name);
|
||||
}
|
||||
|
||||
const static FlatCOption options[] = {
|
||||
const static FlatCOption flatc_options[] = {
|
||||
{ "o", "", "PATH", "Prefix PATH to all generated files." },
|
||||
{ "I", "", "PATH", "Search for includes in the specified path." },
|
||||
{ "M", "", "", "Print make rules for generated files." },
|
||||
@@ -88,6 +93,9 @@ const static FlatCOption options[] = {
|
||||
{ "", "scoped-enums", "",
|
||||
"Use C++11 style scoped and strongly typed enums. Also implies "
|
||||
"--no-prefix." },
|
||||
{ "", "no-emit-min-max-enum-values", "",
|
||||
"Disable generation of MIN and MAX enumerated values for scoped enums "
|
||||
"and prefixed enums." },
|
||||
{ "", "swift-implementation-only", "",
|
||||
"Adds a @_implementationOnly to swift imports" },
|
||||
{ "", "gen-includes", "",
|
||||
@@ -222,7 +230,10 @@ const static FlatCOption options[] = {
|
||||
"Allow a nested_flatbuffer field to be parsed as a vector of bytes "
|
||||
"in JSON, which is unsafe unless checked by a verifier afterwards." },
|
||||
{ "", "ts-flat-files", "",
|
||||
"Only generated one typescript file per .fbs file." },
|
||||
"Generate a single typescript file per .fbs file. Implies "
|
||||
"ts_entry_points." },
|
||||
{ "", "ts-entry-points", "",
|
||||
"Generate entry point typescript per namespace. Implies gen-all." },
|
||||
{ "", "annotate", "SCHEMA",
|
||||
"Annotate the provided BINARY_FILE with the specified SCHEMA file." },
|
||||
{ "", "no-leak-private-annotation", "",
|
||||
@@ -297,15 +308,17 @@ static void AppendShortOption(std::stringstream &ss,
|
||||
if (!option.long_opt.empty()) { ss << "--" << option.long_opt; }
|
||||
}
|
||||
|
||||
std::string FlatCompiler::GetShortUsageString(const char *program_name) const {
|
||||
std::string FlatCompiler::GetShortUsageString(
|
||||
const std::string &program_name) const {
|
||||
std::stringstream ss;
|
||||
ss << "Usage: " << program_name << " [";
|
||||
// TODO(derekbailey): These should be generated from this.generators
|
||||
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||
const Generator &g = params_.generators[i];
|
||||
AppendShortOption(ss, g.option);
|
||||
ss << ", ";
|
||||
}
|
||||
for (const FlatCOption &option : options) {
|
||||
for (const FlatCOption &option : flatc_options) {
|
||||
AppendShortOption(ss, option);
|
||||
ss << ", ";
|
||||
}
|
||||
@@ -317,17 +330,19 @@ std::string FlatCompiler::GetShortUsageString(const char *program_name) const {
|
||||
return ss_textwrap.str();
|
||||
}
|
||||
|
||||
std::string FlatCompiler::GetUsageString(const char *program_name) const {
|
||||
std::string FlatCompiler::GetUsageString(
|
||||
const std::string &program_name) const {
|
||||
std::stringstream ss;
|
||||
ss << "Usage: " << program_name
|
||||
<< " [OPTION]... FILE... [-- BINARY_FILE...]\n";
|
||||
// TODO(derekbailey): These should be generated from this.generators
|
||||
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||
const Generator &g = params_.generators[i];
|
||||
AppendOption(ss, g.option, 80, 25);
|
||||
}
|
||||
|
||||
ss << "\n";
|
||||
for (const FlatCOption &option : options) {
|
||||
for (const FlatCOption &option : flatc_options) {
|
||||
AppendOption(ss, option, 80, 25);
|
||||
}
|
||||
ss << "\n";
|
||||
@@ -338,7 +353,7 @@ std::string FlatCompiler::GetUsageString(const char *program_name) const {
|
||||
"after the -- must be binary flatbuffer format files. Output files are "
|
||||
"named using the base file name of the input, and written to the current "
|
||||
"directory or the path given by -o. example: " +
|
||||
std::string(program_name) + " -c -b schema1.fbs schema2.fbs data.json";
|
||||
program_name + " -c -b schema1.fbs schema2.fbs data.json";
|
||||
AppendTextWrappedString(ss, files_description, 80, 0);
|
||||
ss << "\n";
|
||||
return ss.str();
|
||||
@@ -376,48 +391,34 @@ void FlatCompiler::AnnotateBinaries(
|
||||
}
|
||||
}
|
||||
|
||||
int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
if (params_.generators == nullptr || params_.num_generators == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
FlatCOptions FlatCompiler::ParseFromCommandLineArguments(int argc,
|
||||
const char **argv) {
|
||||
if (argc <= 1) { Error("Need to provide at least one argument."); }
|
||||
|
||||
flatbuffers::IDLOptions opts;
|
||||
std::string output_path;
|
||||
FlatCOptions options;
|
||||
|
||||
bool any_generator = false;
|
||||
bool print_make_rules = false;
|
||||
bool raw_binary = false;
|
||||
bool schema_binary = false;
|
||||
bool grpc_enabled = false;
|
||||
bool requires_bfbs = false;
|
||||
std::vector<std::string> filenames;
|
||||
std::list<std::string> include_directories_storage;
|
||||
std::vector<const char *> include_directories;
|
||||
std::vector<const char *> conform_include_directories;
|
||||
std::vector<bool> generator_enabled(params_.num_generators, false);
|
||||
size_t binary_files_from = std::numeric_limits<size_t>::max();
|
||||
std::string conform_to_schema;
|
||||
std::string annotate_schema;
|
||||
// Default all generates to disabled.
|
||||
options.generator_enabled.resize(params_.num_generators, false);
|
||||
|
||||
const char *program_name = argv[0];
|
||||
options.program_name = std::string(argv[0]);
|
||||
|
||||
IDLOptions &opts = options.opts;
|
||||
|
||||
for (int argi = 1; argi < argc; argi++) {
|
||||
std::string arg = argv[argi];
|
||||
if (arg[0] == '-') {
|
||||
if (filenames.size() && arg[1] != '-')
|
||||
if (options.filenames.size() && arg[1] != '-')
|
||||
Error("invalid option location: " + arg, true);
|
||||
if (arg == "-o") {
|
||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
||||
output_path = flatbuffers::ConCatPathFileName(
|
||||
options.output_path = flatbuffers::ConCatPathFileName(
|
||||
flatbuffers::PosixPath(argv[argi]), "");
|
||||
} else if (arg == "-I") {
|
||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
||||
include_directories_storage.push_back(
|
||||
options.include_directories_storage.push_back(
|
||||
flatbuffers::PosixPath(argv[argi]));
|
||||
include_directories.push_back(
|
||||
include_directories_storage.back().c_str());
|
||||
options.include_directories.push_back(
|
||||
options.include_directories_storage.back().c_str());
|
||||
} else if (arg == "--bfbs-filenames") {
|
||||
if (++argi > argc) Error("missing path following: " + arg, true);
|
||||
opts.project_root = argv[argi];
|
||||
@@ -425,13 +426,13 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
Error(arg + " is not a directory: " + opts.project_root);
|
||||
} else if (arg == "--conform") {
|
||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
||||
conform_to_schema = flatbuffers::PosixPath(argv[argi]);
|
||||
options.conform_to_schema = flatbuffers::PosixPath(argv[argi]);
|
||||
} else if (arg == "--conform-includes") {
|
||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
||||
include_directories_storage.push_back(
|
||||
options.include_directories_storage.push_back(
|
||||
flatbuffers::PosixPath(argv[argi]));
|
||||
conform_include_directories.push_back(
|
||||
include_directories_storage.back().c_str());
|
||||
options.conform_include_directories.push_back(
|
||||
options.include_directories_storage.back().c_str());
|
||||
} else if (arg == "--include-prefix") {
|
||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
||||
opts.include_prefix = flatbuffers::ConCatPathFileName(
|
||||
@@ -464,6 +465,8 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
} else if (arg == "--scoped-enums") {
|
||||
opts.prefixed_enums = false;
|
||||
opts.scoped_enums = true;
|
||||
} else if (arg == "--no-emit-min-max-enum-values") {
|
||||
opts.emit_min_max_enum_values = false;
|
||||
} else if (arg == "--no-union-value-namespacing") {
|
||||
opts.union_value_namespacing = false;
|
||||
} else if (arg == "--gen-mutable") {
|
||||
@@ -526,11 +529,11 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
opts.one_file = true;
|
||||
opts.include_dependence_headers = false;
|
||||
} else if (arg == "--raw-binary") {
|
||||
raw_binary = true;
|
||||
options.raw_binary = true;
|
||||
} else if (arg == "--size-prefixed") {
|
||||
opts.size_prefixed = true;
|
||||
} else if (arg == "--") { // Separator between text and binary inputs.
|
||||
binary_files_from = filenames.size();
|
||||
options.binary_files_from = options.filenames.size();
|
||||
} else if (arg == "--proto") {
|
||||
opts.proto_mode = true;
|
||||
} else if (arg == "--proto-namespace-suffix") {
|
||||
@@ -539,17 +542,17 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
} else if (arg == "--oneof-union") {
|
||||
opts.proto_oneof_union = true;
|
||||
} else if (arg == "--schema") {
|
||||
schema_binary = true;
|
||||
options.schema_binary = true;
|
||||
} else if (arg == "-M") {
|
||||
print_make_rules = true;
|
||||
options.print_make_rules = true;
|
||||
} else if (arg == "--version") {
|
||||
printf("flatc version %s\n", FLATC_VERSION());
|
||||
exit(0);
|
||||
} else if (arg == "--help" || arg == "-h") {
|
||||
printf("%s\n", GetUsageString(program_name).c_str());
|
||||
printf("%s\n", GetUsageString(options.program_name).c_str());
|
||||
exit(0);
|
||||
} else if (arg == "--grpc") {
|
||||
grpc_enabled = true;
|
||||
options.grpc_enabled = true;
|
||||
} else if (arg == "--bfbs-comments") {
|
||||
opts.binary_schema_comments = true;
|
||||
} else if (arg == "--bfbs-builtins") {
|
||||
@@ -607,42 +610,76 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
} else if (arg == "--json-nested-bytes") {
|
||||
opts.json_nested_legacy_flatbuffers = true;
|
||||
} else if (arg == "--ts-flat-files") {
|
||||
opts.ts_flat_file = true;
|
||||
opts.ts_flat_files = true;
|
||||
opts.ts_entry_points = true;
|
||||
opts.generate_all = true;
|
||||
} else if (arg == "--ts-entry-points") {
|
||||
opts.ts_entry_points = true;
|
||||
opts.generate_all = true;
|
||||
} else if (arg == "--ts-no-import-ext") {
|
||||
opts.ts_no_import_ext = true;
|
||||
} else if (arg == "--no-leak-private-annotation") {
|
||||
opts.no_leak_private_annotations = true;
|
||||
} else if (arg == "--annotate") {
|
||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
||||
annotate_schema = flatbuffers::PosixPath(argv[argi]);
|
||||
options.annotate_schema = flatbuffers::PosixPath(argv[argi]);
|
||||
} else {
|
||||
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||
if (arg == "--" + params_.generators[i].option.long_opt ||
|
||||
arg == "-" + params_.generators[i].option.short_opt) {
|
||||
generator_enabled[i] = true;
|
||||
any_generator = true;
|
||||
opts.lang_to_generate |= params_.generators[i].lang;
|
||||
if (params_.generators[i].bfbs_generator) {
|
||||
opts.binary_schema_comments = true;
|
||||
requires_bfbs = true;
|
||||
}
|
||||
goto found;
|
||||
// Look up if the command line argument refers to a code generator.
|
||||
auto code_generator_it = code_generators_.find(arg);
|
||||
if (code_generator_it != code_generators_.end()) {
|
||||
std::shared_ptr<CodeGenerator> code_generator =
|
||||
code_generator_it->second;
|
||||
|
||||
// TODO(derekbailey): remove in favor of just checking if
|
||||
// generators.empty().
|
||||
options.any_generator = true;
|
||||
opts.lang_to_generate |= code_generator->Language();
|
||||
|
||||
if (code_generator->SupportsBfbsGeneration()) {
|
||||
opts.binary_schema_comments = true;
|
||||
options.requires_bfbs = true;
|
||||
}
|
||||
|
||||
options.generators.push_back(std::move(code_generator));
|
||||
} else {
|
||||
// TODO(derekbailey): deprecate the following logic in favor of the
|
||||
// code generator map above.
|
||||
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||
if (arg == "--" + params_.generators[i].option.long_opt ||
|
||||
arg == "-" + params_.generators[i].option.short_opt) {
|
||||
options.generator_enabled[i] = true;
|
||||
options.any_generator = true;
|
||||
opts.lang_to_generate |= params_.generators[i].lang;
|
||||
if (params_.generators[i].bfbs_generator) {
|
||||
opts.binary_schema_comments = true;
|
||||
options.requires_bfbs = true;
|
||||
}
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
Error("unknown commandline argument: " + arg, true);
|
||||
}
|
||||
Error("unknown commandline argument: " + arg, true);
|
||||
|
||||
found:;
|
||||
}
|
||||
} else {
|
||||
filenames.push_back(flatbuffers::PosixPath(argv[argi]));
|
||||
options.filenames.push_back(flatbuffers::PosixPath(argv[argi]));
|
||||
}
|
||||
}
|
||||
|
||||
if (!filenames.size()) Error("missing input files", false, true);
|
||||
return options;
|
||||
}
|
||||
|
||||
void FlatCompiler::ValidateOptions(const FlatCOptions &options) {
|
||||
const IDLOptions &opts = options.opts;
|
||||
|
||||
if (!options.filenames.size()) Error("missing input files", false, true);
|
||||
|
||||
if (opts.proto_mode) {
|
||||
if (any_generator)
|
||||
if (options.any_generator)
|
||||
Error("cannot generate code directly from .proto files", true);
|
||||
} else if (!any_generator && conform_to_schema.empty() &&
|
||||
annotate_schema.empty()) {
|
||||
} else if (!options.any_generator && options.conform_to_schema.empty() &&
|
||||
options.annotate_schema.empty()) {
|
||||
Error("no options: specify at least one generator.", true);
|
||||
}
|
||||
|
||||
@@ -651,80 +688,45 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
"--cs-gen-json-serializer requires --gen-object-api to be set as "
|
||||
"well.");
|
||||
}
|
||||
}
|
||||
|
||||
flatbuffers::Parser FlatCompiler::GetConformParser(
|
||||
const FlatCOptions &options) {
|
||||
flatbuffers::Parser conform_parser;
|
||||
if (!conform_to_schema.empty()) {
|
||||
if (!options.conform_to_schema.empty()) {
|
||||
std::string contents;
|
||||
if (!flatbuffers::LoadFile(conform_to_schema.c_str(), true, &contents))
|
||||
Error("unable to load schema: " + conform_to_schema);
|
||||
if (!flatbuffers::LoadFile(options.conform_to_schema.c_str(), true,
|
||||
&contents)) {
|
||||
Error("unable to load schema: " + options.conform_to_schema);
|
||||
}
|
||||
|
||||
if (flatbuffers::GetExtension(conform_to_schema) ==
|
||||
if (flatbuffers::GetExtension(options.conform_to_schema) ==
|
||||
reflection::SchemaExtension()) {
|
||||
LoadBinarySchema(conform_parser, conform_to_schema, contents);
|
||||
LoadBinarySchema(conform_parser, options.conform_to_schema, contents);
|
||||
} else {
|
||||
ParseFile(conform_parser, conform_to_schema, contents,
|
||||
conform_include_directories);
|
||||
ParseFile(conform_parser, options.conform_to_schema, contents,
|
||||
options.conform_include_directories);
|
||||
}
|
||||
}
|
||||
return conform_parser;
|
||||
}
|
||||
|
||||
if (!annotate_schema.empty()) {
|
||||
const std::string ext = flatbuffers::GetExtension(annotate_schema);
|
||||
if (!(ext == reflection::SchemaExtension() || ext == "fbs")) {
|
||||
Error("Expected a `.bfbs` or `.fbs` schema, got: " + annotate_schema);
|
||||
}
|
||||
std::unique_ptr<Parser> FlatCompiler::GenerateCode(const FlatCOptions &options,
|
||||
Parser &conform_parser) {
|
||||
std::unique_ptr<Parser> parser =
|
||||
std::unique_ptr<Parser>(new Parser(options.opts));
|
||||
|
||||
const bool is_binary_schema = ext == reflection::SchemaExtension();
|
||||
for (auto file_it = options.filenames.begin();
|
||||
file_it != options.filenames.end(); ++file_it) {
|
||||
IDLOptions opts = options.opts;
|
||||
|
||||
std::string schema_contents;
|
||||
if (!flatbuffers::LoadFile(annotate_schema.c_str(),
|
||||
/*binary=*/is_binary_schema, &schema_contents)) {
|
||||
Error("unable to load schema: " + annotate_schema);
|
||||
}
|
||||
|
||||
const uint8_t *binary_schema = nullptr;
|
||||
uint64_t binary_schema_size = 0;
|
||||
|
||||
IDLOptions binary_opts;
|
||||
binary_opts.lang_to_generate |= flatbuffers::IDLOptions::kBinary;
|
||||
flatbuffers::Parser parser(binary_opts);
|
||||
|
||||
if (is_binary_schema) {
|
||||
binary_schema =
|
||||
reinterpret_cast<const uint8_t *>(schema_contents.c_str());
|
||||
binary_schema_size = schema_contents.size();
|
||||
} else {
|
||||
// If we need to generate the .bfbs file from the provided schema file
|
||||
// (.fbs)
|
||||
ParseFile(parser, annotate_schema, schema_contents, include_directories);
|
||||
parser.Serialize();
|
||||
|
||||
binary_schema = parser.builder_.GetBufferPointer();
|
||||
binary_schema_size = parser.builder_.GetSize();
|
||||
}
|
||||
|
||||
if (binary_schema == nullptr || !binary_schema_size) {
|
||||
Error("could not parse a value binary schema from: " + annotate_schema);
|
||||
}
|
||||
|
||||
// Annotate the provided files with the binary_schema.
|
||||
AnnotateBinaries(binary_schema, binary_schema_size, annotate_schema,
|
||||
filenames);
|
||||
|
||||
// We don't support doing anything else after annotating a binary.
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::unique_ptr<flatbuffers::Parser> parser(new flatbuffers::Parser(opts));
|
||||
|
||||
for (auto file_it = filenames.begin(); file_it != filenames.end();
|
||||
++file_it) {
|
||||
auto &filename = *file_it;
|
||||
std::string contents;
|
||||
if (!flatbuffers::LoadFile(filename.c_str(), true, &contents))
|
||||
Error("unable to load file: " + filename);
|
||||
|
||||
bool is_binary =
|
||||
static_cast<size_t>(file_it - filenames.begin()) >= binary_files_from;
|
||||
bool is_binary = static_cast<size_t>(file_it - options.filenames.begin()) >=
|
||||
options.binary_files_from;
|
||||
auto ext = flatbuffers::GetExtension(filename);
|
||||
const bool is_schema = ext == "fbs" || ext == "proto";
|
||||
if (is_schema && opts.project_root.empty()) {
|
||||
@@ -736,7 +738,7 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
parser->builder_.PushFlatBuffer(
|
||||
reinterpret_cast<const uint8_t *>(contents.c_str()),
|
||||
contents.length());
|
||||
if (!raw_binary) {
|
||||
if (!options.raw_binary) {
|
||||
// Generally reading binaries that do not correspond to the schema
|
||||
// will crash, and sadly there's no way around that when the binary
|
||||
// does not contain a file identifier.
|
||||
@@ -766,12 +768,12 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
// If we're processing multiple schemas, make sure to start each
|
||||
// one from scratch. If it depends on previous schemas it must do
|
||||
// so explicitly using an include.
|
||||
parser.reset(new flatbuffers::Parser(opts));
|
||||
parser.reset(new Parser(opts));
|
||||
}
|
||||
// Try to parse the file contents (binary schema/flexbuffer/textual
|
||||
// schema)
|
||||
if (is_binary_schema) {
|
||||
LoadBinarySchema(*parser.get(), filename, contents);
|
||||
LoadBinarySchema(*parser, filename, contents);
|
||||
} else if (opts.use_flexbuffers) {
|
||||
if (opts.lang_to_generate == IDLOptions::kJson) {
|
||||
auto data = reinterpret_cast<const uint8_t *>(contents.c_str());
|
||||
@@ -782,10 +784,10 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
parser->flex_root_ = flexbuffers::GetRoot(data, size);
|
||||
} else {
|
||||
parser->flex_builder_.Clear();
|
||||
ParseFile(*parser.get(), filename, contents, include_directories);
|
||||
ParseFile(*parser, filename, contents, options.include_directories);
|
||||
}
|
||||
} else {
|
||||
ParseFile(*parser.get(), filename, contents, include_directories);
|
||||
ParseFile(*parser, filename, contents, options.include_directories);
|
||||
if (!is_schema && !parser->builder_.GetSize()) {
|
||||
// If a file doesn't end in .fbs, it must be json/binary. Ensure we
|
||||
// didn't just parse a schema with a different extension.
|
||||
@@ -794,14 +796,15 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
true);
|
||||
}
|
||||
}
|
||||
if ((is_schema || is_binary_schema) && !conform_to_schema.empty()) {
|
||||
if ((is_schema || is_binary_schema) &&
|
||||
!options.conform_to_schema.empty()) {
|
||||
auto err = parser->ConformTo(conform_parser);
|
||||
if (!err.empty()) Error("schemas don\'t conform: " + err, false);
|
||||
}
|
||||
if (schema_binary || opts.binary_schema_gen_embed) {
|
||||
if (options.schema_binary || opts.binary_schema_gen_embed) {
|
||||
parser->Serialize();
|
||||
}
|
||||
if (schema_binary) {
|
||||
if (options.schema_binary) {
|
||||
parser->file_extension_ = reflection::SchemaExtension();
|
||||
}
|
||||
}
|
||||
@@ -812,16 +815,67 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
// the serialized buffer and length.
|
||||
const uint8_t *bfbs_buffer = nullptr;
|
||||
int64_t bfbs_length = 0;
|
||||
if (requires_bfbs) {
|
||||
if (options.requires_bfbs) {
|
||||
parser->Serialize();
|
||||
bfbs_buffer = parser->builder_.GetBufferPointer();
|
||||
bfbs_length = parser->builder_.GetSize();
|
||||
}
|
||||
|
||||
for (const std::shared_ptr<CodeGenerator> &code_generator :
|
||||
options.generators) {
|
||||
if (options.print_make_rules) {
|
||||
std::string make_rule;
|
||||
const CodeGenerator::Status status = code_generator->GenerateMakeRule(
|
||||
*parser, options.output_path, filename, make_rule);
|
||||
if (status == CodeGenerator::Status::OK && !make_rule.empty()) {
|
||||
printf("%s\n",
|
||||
flatbuffers::WordWrap(make_rule, 80, " ", " \\").c_str());
|
||||
} else {
|
||||
Error("Cannot generate make rule for " +
|
||||
code_generator->LanguageName());
|
||||
}
|
||||
} else {
|
||||
flatbuffers::EnsureDirExists(options.output_path);
|
||||
|
||||
// Prefer bfbs generators if present.
|
||||
if (code_generator->SupportsBfbsGeneration()) {
|
||||
const CodeGenerator::Status status =
|
||||
code_generator->GenerateCode(bfbs_buffer, bfbs_length);
|
||||
if (status != CodeGenerator::Status::OK) {
|
||||
Error("Unable to generate " + code_generator->LanguageName() +
|
||||
" for " + filebase + " using bfbs generator.");
|
||||
}
|
||||
} else {
|
||||
if ((!code_generator->IsSchemaOnly() ||
|
||||
(is_schema || is_binary_schema)) &&
|
||||
code_generator->GenerateCode(*parser, options.output_path,
|
||||
filebase) !=
|
||||
CodeGenerator::Status::OK) {
|
||||
Error("Unable to generate " + code_generator->LanguageName() +
|
||||
" for " + filebase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (options.grpc_enabled) {
|
||||
const CodeGenerator::Status status = code_generator->GenerateGrpcCode(
|
||||
*parser, options.output_path, filebase);
|
||||
|
||||
if (status == CodeGenerator::Status::NOT_IMPLEMENTED) {
|
||||
Warn("GRPC interface generator not implemented for " +
|
||||
code_generator->LanguageName());
|
||||
} else if (status == CodeGenerator::Status::ERROR) {
|
||||
Error("Unable to generate GRPC interface for " +
|
||||
code_generator->LanguageName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(derekbailey): Deprecate the following in favor to the above.
|
||||
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||
if (generator_enabled[i]) {
|
||||
if (!print_make_rules) {
|
||||
flatbuffers::EnsureDirExists(output_path);
|
||||
if (options.generator_enabled[i]) {
|
||||
if (!options.print_make_rules) {
|
||||
flatbuffers::EnsureDirExists(options.output_path);
|
||||
|
||||
// Prefer bfbs generators if present.
|
||||
if (params_.generators[i].bfbs_generator) {
|
||||
@@ -836,7 +890,7 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
} else {
|
||||
if ((!params_.generators[i].schema_only ||
|
||||
(is_schema || is_binary_schema)) &&
|
||||
!params_.generators[i].generate(*parser.get(), output_path,
|
||||
!params_.generators[i].generate(*parser, options.output_path,
|
||||
filebase)) {
|
||||
Error(std::string("Unable to generate ") +
|
||||
params_.generators[i].lang_name + " for " + filebase);
|
||||
@@ -848,16 +902,16 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
params_.generators[i].lang_name);
|
||||
} else {
|
||||
std::string make_rule = params_.generators[i].make_rule(
|
||||
*parser.get(), output_path, filename);
|
||||
*parser, options.output_path, filename);
|
||||
if (!make_rule.empty())
|
||||
printf("%s\n",
|
||||
flatbuffers::WordWrap(make_rule, 80, " ", " \\").c_str());
|
||||
}
|
||||
}
|
||||
if (grpc_enabled) {
|
||||
if (options.grpc_enabled) {
|
||||
if (params_.generators[i].generateGRPC != nullptr) {
|
||||
if (!params_.generators[i].generateGRPC(*parser.get(), output_path,
|
||||
filebase)) {
|
||||
if (!params_.generators[i].generateGRPC(
|
||||
*parser, options.output_path, filebase)) {
|
||||
Error(std::string("Unable to generate GRPC interface for ") +
|
||||
params_.generators[i].lang_name);
|
||||
}
|
||||
@@ -876,19 +930,84 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
Error("root type must be a table");
|
||||
}
|
||||
|
||||
if (opts.proto_mode) GenerateFBS(*parser.get(), output_path, filebase);
|
||||
if (opts.proto_mode) GenerateFBS(*parser, options.output_path, filebase);
|
||||
|
||||
// We do not want to generate code for the definitions in this file
|
||||
// in any files coming up next.
|
||||
parser->MarkGenerated();
|
||||
}
|
||||
|
||||
return parser;
|
||||
}
|
||||
|
||||
int FlatCompiler::Compile(const FlatCOptions &options) {
|
||||
if (params_.generators == nullptr || params_.num_generators == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO(derekbailey): change to std::optional<Parser>
|
||||
Parser conform_parser = GetConformParser(options);
|
||||
|
||||
// TODO(derekbailey): split to own method.
|
||||
if (!options.annotate_schema.empty()) {
|
||||
const std::string ext = flatbuffers::GetExtension(options.annotate_schema);
|
||||
if (!(ext == reflection::SchemaExtension() || ext == "fbs")) {
|
||||
Error("Expected a `.bfbs` or `.fbs` schema, got: " +
|
||||
options.annotate_schema);
|
||||
}
|
||||
|
||||
const bool is_binary_schema = ext == reflection::SchemaExtension();
|
||||
|
||||
std::string schema_contents;
|
||||
if (!flatbuffers::LoadFile(options.annotate_schema.c_str(),
|
||||
/*binary=*/is_binary_schema, &schema_contents)) {
|
||||
Error("unable to load schema: " + options.annotate_schema);
|
||||
}
|
||||
|
||||
const uint8_t *binary_schema = nullptr;
|
||||
uint64_t binary_schema_size = 0;
|
||||
|
||||
IDLOptions binary_opts;
|
||||
binary_opts.lang_to_generate |= flatbuffers::IDLOptions::kBinary;
|
||||
Parser parser(binary_opts);
|
||||
|
||||
if (is_binary_schema) {
|
||||
binary_schema =
|
||||
reinterpret_cast<const uint8_t *>(schema_contents.c_str());
|
||||
binary_schema_size = schema_contents.size();
|
||||
} else {
|
||||
// If we need to generate the .bfbs file from the provided schema file
|
||||
// (.fbs)
|
||||
ParseFile(parser, options.annotate_schema, schema_contents,
|
||||
options.include_directories);
|
||||
parser.Serialize();
|
||||
|
||||
binary_schema = parser.builder_.GetBufferPointer();
|
||||
binary_schema_size = parser.builder_.GetSize();
|
||||
}
|
||||
|
||||
if (binary_schema == nullptr || !binary_schema_size) {
|
||||
Error("could not parse a value binary schema from: " +
|
||||
options.annotate_schema);
|
||||
}
|
||||
|
||||
// Annotate the provided files with the binary_schema.
|
||||
AnnotateBinaries(binary_schema, binary_schema_size, options.annotate_schema,
|
||||
options.filenames);
|
||||
|
||||
// We don't support doing anything else after annotating a binary.
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::unique_ptr<Parser> parser = GenerateCode(options, conform_parser);
|
||||
|
||||
// Once all the files have been parsed, run any generators Parsing Completed
|
||||
// function for final generation.
|
||||
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||
if (generator_enabled[i] &&
|
||||
if (options.generator_enabled[i] &&
|
||||
params_.generators[i].parsing_completed != nullptr) {
|
||||
if (!params_.generators[i].parsing_completed(*parser, output_path)) {
|
||||
if (!params_.generators[i].parsing_completed(*parser,
|
||||
options.output_path)) {
|
||||
Error("failed running parsing completed for " +
|
||||
std::string(params_.generators[i].lang_name));
|
||||
}
|
||||
@@ -898,4 +1017,14 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool FlatCompiler::RegisterCodeGenerator(
|
||||
const std::string &flag, std::shared_ptr<CodeGenerator> code_generator) {
|
||||
if (code_generators_.find(flag) != code_generators_.end()) {
|
||||
Error("multiple generators registered under: " + flag, false, false);
|
||||
return false;
|
||||
}
|
||||
code_generators_[flag] = std::move(code_generator);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
@@ -20,9 +20,12 @@
|
||||
#include "bfbs_gen_lua.h"
|
||||
#include "bfbs_gen_nim.h"
|
||||
#include "flatbuffers/base.h"
|
||||
#include "flatbuffers/code_generator.h"
|
||||
#include "flatbuffers/flatc.h"
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
|
||||
|
||||
static const char *g_program_name = nullptr;
|
||||
|
||||
static void Warn(const flatbuffers::FlatCompiler *flatc,
|
||||
@@ -158,5 +161,17 @@ int main(int argc, const char *argv[]) {
|
||||
params.error_fn = Error;
|
||||
|
||||
flatbuffers::FlatCompiler flatc(params);
|
||||
return flatc.Compile(argc, argv);
|
||||
|
||||
std::shared_ptr<flatbuffers::CodeGenerator> cpp_generator =
|
||||
flatbuffers::NewCppCodeGenerator();
|
||||
|
||||
flatc.RegisterCodeGenerator("--cpp", cpp_generator);
|
||||
flatc.RegisterCodeGenerator("-c", cpp_generator);
|
||||
|
||||
// Create the FlatC options by parsing the command line arguments.
|
||||
const flatbuffers::FlatCOptions &options =
|
||||
flatc.ParseFromCommandLineArguments(argc, argv);
|
||||
|
||||
// Compile with the extracted FlatC options.
|
||||
return flatc.Compile(options);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
// independent from idl_parser, since this code is not needed for most clients
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
@@ -90,7 +91,7 @@ enum CppStandard { CPP_STD_X0 = 0, CPP_STD_11, CPP_STD_17 };
|
||||
// Define a style of 'struct' constructor if it has 'Array' fields.
|
||||
enum GenArrayArgMode {
|
||||
kArrayArgModeNone, // don't generate initialization args
|
||||
kArrayArgModeSpanStatic, // generate flatbuffers::span<T,N>
|
||||
kArrayArgModeSpanStatic, // generate ::flatbuffers::span<T,N>
|
||||
};
|
||||
|
||||
// Extension of IDLOptions for cpp-generator.
|
||||
@@ -252,14 +253,13 @@ class CppGenerator : public BaseGenerator {
|
||||
// Get the name of the included file as defined by the schema, and strip
|
||||
// the .fbs extension.
|
||||
const std::string name_without_ext =
|
||||
flatbuffers::StripExtension(included_file.schema_name);
|
||||
StripExtension(included_file.schema_name);
|
||||
|
||||
// If we are told to keep the prefix of the included schema, leave it
|
||||
// unchanged, otherwise strip the leading path off so just the "basename"
|
||||
// of the include is retained.
|
||||
const std::string basename =
|
||||
opts_.keep_prefix ? name_without_ext
|
||||
: flatbuffers::StripPath(name_without_ext);
|
||||
opts_.keep_prefix ? name_without_ext : StripPath(name_without_ext);
|
||||
|
||||
code_ += "#include \"" +
|
||||
GeneratedFileName(opts_.include_prefix, basename, opts_) + "\"";
|
||||
@@ -522,7 +522,7 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ +=
|
||||
"const {{CPP_NAME}} *{{NULLABLE_EXT}}Get{{STRUCT_NAME}}(const void "
|
||||
"*buf) {";
|
||||
code_ += " return flatbuffers::GetRoot<{{CPP_NAME}}>(buf);";
|
||||
code_ += " return ::flatbuffers::GetRoot<{{CPP_NAME}}>(buf);";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
|
||||
@@ -531,14 +531,16 @@ class CppGenerator : public BaseGenerator {
|
||||
"const {{CPP_NAME}} "
|
||||
"*{{NULLABLE_EXT}}GetSizePrefixed{{STRUCT_NAME}}(const void "
|
||||
"*buf) {";
|
||||
code_ += " return flatbuffers::GetSizePrefixedRoot<{{CPP_NAME}}>(buf);";
|
||||
code_ +=
|
||||
" return ::flatbuffers::GetSizePrefixedRoot<{{CPP_NAME}}>(buf);";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
|
||||
if (opts_.mutable_buffer) {
|
||||
code_ += "inline \\";
|
||||
code_ += "{{STRUCT_NAME}} *GetMutable{{STRUCT_NAME}}(void *buf) {";
|
||||
code_ += " return flatbuffers::GetMutableRoot<{{STRUCT_NAME}}>(buf);";
|
||||
code_ +=
|
||||
" return ::flatbuffers::GetMutableRoot<{{STRUCT_NAME}}>(buf);";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
|
||||
@@ -549,7 +551,7 @@ class CppGenerator : public BaseGenerator {
|
||||
"*buf) {";
|
||||
code_ +=
|
||||
" return "
|
||||
"flatbuffers::GetMutableSizePrefixedRoot<{{CPP_NAME}}>(buf);";
|
||||
"::flatbuffers::GetMutableSizePrefixedRoot<{{CPP_NAME}}>(buf);";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
}
|
||||
@@ -564,7 +566,7 @@ class CppGenerator : public BaseGenerator {
|
||||
// Check if a buffer has the identifier.
|
||||
code_ += "inline \\";
|
||||
code_ += "bool {{STRUCT_NAME}}BufferHasIdentifier(const void *buf) {";
|
||||
code_ += " return flatbuffers::BufferHasIdentifier(";
|
||||
code_ += " return ::flatbuffers::BufferHasIdentifier(";
|
||||
code_ += " buf, {{STRUCT_NAME}}Identifier());";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
@@ -574,7 +576,7 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ +=
|
||||
"bool SizePrefixed{{STRUCT_NAME}}BufferHasIdentifier(const void "
|
||||
"*buf) {";
|
||||
code_ += " return flatbuffers::BufferHasIdentifier(";
|
||||
code_ += " return ::flatbuffers::BufferHasIdentifier(";
|
||||
code_ += " buf, {{STRUCT_NAME}}Identifier(), true);";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
@@ -588,13 +590,13 @@ class CppGenerator : public BaseGenerator {
|
||||
}
|
||||
|
||||
code_ += "inline bool Verify{{STRUCT_NAME}}Buffer(";
|
||||
code_ += " flatbuffers::Verifier &verifier) {";
|
||||
code_ += " ::flatbuffers::Verifier &verifier) {";
|
||||
code_ += " return verifier.VerifyBuffer<{{CPP_NAME}}>({{ID}});";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
|
||||
code_ += "inline bool VerifySizePrefixed{{STRUCT_NAME}}Buffer(";
|
||||
code_ += " flatbuffers::Verifier &verifier) {";
|
||||
code_ += " ::flatbuffers::Verifier &verifier) {";
|
||||
code_ +=
|
||||
" return verifier.VerifySizePrefixedBuffer<{{CPP_NAME}}>({{ID}});";
|
||||
code_ += "}";
|
||||
@@ -610,8 +612,8 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
// Finish a buffer with a given root object:
|
||||
code_ += "inline void Finish{{STRUCT_NAME}}Buffer(";
|
||||
code_ += " flatbuffers::FlatBufferBuilder &fbb,";
|
||||
code_ += " flatbuffers::Offset<{{CPP_NAME}}> root) {";
|
||||
code_ += " ::flatbuffers::FlatBufferBuilder &fbb,";
|
||||
code_ += " ::flatbuffers::Offset<{{CPP_NAME}}> root) {";
|
||||
if (parser_.file_identifier_.length())
|
||||
code_ += " fbb.Finish(root, {{STRUCT_NAME}}Identifier());";
|
||||
else
|
||||
@@ -620,8 +622,8 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ += "";
|
||||
|
||||
code_ += "inline void FinishSizePrefixed{{STRUCT_NAME}}Buffer(";
|
||||
code_ += " flatbuffers::FlatBufferBuilder &fbb,";
|
||||
code_ += " flatbuffers::Offset<{{CPP_NAME}}> root) {";
|
||||
code_ += " ::flatbuffers::FlatBufferBuilder &fbb,";
|
||||
code_ += " ::flatbuffers::Offset<{{CPP_NAME}}> root) {";
|
||||
if (parser_.file_identifier_.length())
|
||||
code_ += " fbb.FinishSizePrefixed(root, {{STRUCT_NAME}}Identifier());";
|
||||
else
|
||||
@@ -639,7 +641,8 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
code_ += "inline {{UNPACK_RETURN}} UnPack{{STRUCT_NAME}}(";
|
||||
code_ += " const void *buf,";
|
||||
code_ += " const flatbuffers::resolver_function_t *res = nullptr) {";
|
||||
code_ +=
|
||||
" const ::flatbuffers::resolver_function_t *res = nullptr) {";
|
||||
code_ += " return {{UNPACK_TYPE}}\\";
|
||||
code_ += "(Get{{STRUCT_NAME}}(buf)->UnPack(res));";
|
||||
code_ += "}";
|
||||
@@ -647,7 +650,8 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
code_ += "inline {{UNPACK_RETURN}} UnPackSizePrefixed{{STRUCT_NAME}}(";
|
||||
code_ += " const void *buf,";
|
||||
code_ += " const flatbuffers::resolver_function_t *res = nullptr) {";
|
||||
code_ +=
|
||||
" const ::flatbuffers::resolver_function_t *res = nullptr) {";
|
||||
code_ += " return {{UNPACK_TYPE}}\\";
|
||||
code_ += "(GetSizePrefixed{{STRUCT_NAME}}(buf)->UnPack(res));";
|
||||
code_ += "}";
|
||||
@@ -735,12 +739,12 @@ class CppGenerator : public BaseGenerator {
|
||||
std::string GenTypePointer(const Type &type) const {
|
||||
switch (type.base_type) {
|
||||
case BASE_TYPE_STRING: {
|
||||
return "flatbuffers::String";
|
||||
return "::flatbuffers::String";
|
||||
}
|
||||
case BASE_TYPE_VECTOR: {
|
||||
const auto type_name = GenTypeWire(
|
||||
type.VectorType(), "", VectorElementUserFacing(type.VectorType()));
|
||||
return "flatbuffers::Vector<" + type_name + ">";
|
||||
return "::flatbuffers::Vector<" + type_name + ">";
|
||||
}
|
||||
case BASE_TYPE_STRUCT: {
|
||||
return WrapInNameSpace(*type.struct_def);
|
||||
@@ -762,7 +766,7 @@ class CppGenerator : public BaseGenerator {
|
||||
} else if (IsStruct(type)) {
|
||||
return "const " + GenTypePointer(type) + " *";
|
||||
} else {
|
||||
return "flatbuffers::Offset<" + GenTypePointer(type) + ">" + postfix;
|
||||
return "::flatbuffers::Offset<" + GenTypePointer(type) + ">" + postfix;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -774,7 +778,7 @@ class CppGenerator : public BaseGenerator {
|
||||
} else if (IsStruct(type)) {
|
||||
return GenTypePointer(type);
|
||||
} else {
|
||||
return "flatbuffers::uoffset_t";
|
||||
return "::flatbuffers::uoffset_t";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -807,7 +811,8 @@ class CppGenerator : public BaseGenerator {
|
||||
}
|
||||
|
||||
bool FlexibleStringConstructor(const FieldDef *field) {
|
||||
auto attr = field != nullptr && (field->attributes.Lookup("cpp_str_flex_ctor") != nullptr);
|
||||
auto attr = field != nullptr &&
|
||||
(field->attributes.Lookup("cpp_str_flex_ctor") != nullptr);
|
||||
auto ret = attr ? attr : opts_.cpp_object_api_string_flexible_constructor;
|
||||
return ret && NativeString(field) !=
|
||||
"std::string"; // Only for custom string types.
|
||||
@@ -835,10 +840,10 @@ class CppGenerator : public BaseGenerator {
|
||||
return ptr_type == "naked" ? "" : ".get()";
|
||||
}
|
||||
|
||||
std::string GenOptionalNull() { return "flatbuffers::nullopt"; }
|
||||
std::string GenOptionalNull() { return "::flatbuffers::nullopt"; }
|
||||
|
||||
std::string GenOptionalDecl(const Type &type) {
|
||||
return "flatbuffers::Optional<" + GenTypeBasic(type, true) + ">";
|
||||
return "::flatbuffers::Optional<" + GenTypeBasic(type, true) + ">";
|
||||
}
|
||||
|
||||
std::string GenTypeNative(const Type &type, bool invector,
|
||||
@@ -912,10 +917,10 @@ class CppGenerator : public BaseGenerator {
|
||||
}
|
||||
|
||||
std::string GenTypeSpan(const Type &type, bool immutable, size_t extent) {
|
||||
// Generate "flatbuffers::span<const U, extent>".
|
||||
// Generate "::flatbuffers::span<const U, extent>".
|
||||
FLATBUFFERS_ASSERT(IsSeries(type) && "unexpected type");
|
||||
auto element_type = type.VectorType();
|
||||
std::string text = "flatbuffers::span<";
|
||||
std::string text = "::flatbuffers::span<";
|
||||
text += immutable ? "const " : "";
|
||||
if (IsScalar(element_type.base_type)) {
|
||||
text += GenTypeBasic(element_type, IsEnum(element_type));
|
||||
@@ -935,7 +940,7 @@ class CppGenerator : public BaseGenerator {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (extent != flatbuffers::dynamic_extent) {
|
||||
if (extent != dynamic_extent) {
|
||||
text += ", ";
|
||||
text += NumToString(extent);
|
||||
}
|
||||
@@ -972,7 +977,7 @@ class CppGenerator : public BaseGenerator {
|
||||
}
|
||||
return WrapInNameSpace(ev.union_type.struct_def->defined_namespace, name);
|
||||
} else if (IsString(ev.union_type)) {
|
||||
return native_type ? "std::string" : "flatbuffers::String";
|
||||
return native_type ? "std::string" : "::flatbuffers::String";
|
||||
} else {
|
||||
FLATBUFFERS_ASSERT(false);
|
||||
return Name(ev);
|
||||
@@ -981,7 +986,7 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
std::string UnionVerifySignature(const EnumDef &enum_def) {
|
||||
return "bool Verify" + Name(enum_def) +
|
||||
"(flatbuffers::Verifier &verifier, const void *obj, " +
|
||||
"(::flatbuffers::Verifier &verifier, const void *obj, " +
|
||||
Name(enum_def) + " type)";
|
||||
}
|
||||
|
||||
@@ -989,42 +994,44 @@ class CppGenerator : public BaseGenerator {
|
||||
auto name = Name(enum_def);
|
||||
auto type = opts_.scoped_enums ? name : "uint8_t";
|
||||
return "bool Verify" + name + "Vector" +
|
||||
"(flatbuffers::Verifier &verifier, " +
|
||||
"const flatbuffers::Vector<flatbuffers::Offset<void>> *values, " +
|
||||
"const flatbuffers::Vector<" + type + "> *types)";
|
||||
"(::flatbuffers::Verifier &verifier, " +
|
||||
"const ::flatbuffers::Vector<::flatbuffers::Offset<void>> "
|
||||
"*values, " +
|
||||
"const ::flatbuffers::Vector<" + type + "> *types)";
|
||||
}
|
||||
|
||||
std::string UnionUnPackSignature(const EnumDef &enum_def, bool inclass) {
|
||||
return (inclass ? "static " : "") + std::string("void *") +
|
||||
(inclass ? "" : Name(enum_def) + "Union::") +
|
||||
"UnPack(const void *obj, " + Name(enum_def) +
|
||||
" type, const flatbuffers::resolver_function_t *resolver)";
|
||||
" type, const ::flatbuffers::resolver_function_t *resolver)";
|
||||
}
|
||||
|
||||
std::string UnionPackSignature(const EnumDef &enum_def, bool inclass) {
|
||||
return "flatbuffers::Offset<void> " +
|
||||
return "::flatbuffers::Offset<void> " +
|
||||
(inclass ? "" : Name(enum_def) + "Union::") +
|
||||
"Pack(flatbuffers::FlatBufferBuilder &_fbb, " +
|
||||
"const flatbuffers::rehasher_function_t *_rehasher" +
|
||||
"Pack(::flatbuffers::FlatBufferBuilder &_fbb, " +
|
||||
"const ::flatbuffers::rehasher_function_t *_rehasher" +
|
||||
(inclass ? " = nullptr" : "") + ") const";
|
||||
}
|
||||
|
||||
std::string TableCreateSignature(const StructDef &struct_def, bool predecl,
|
||||
const IDLOptions &opts) {
|
||||
return "flatbuffers::Offset<" + Name(struct_def) + "> Create" +
|
||||
Name(struct_def) + "(flatbuffers::FlatBufferBuilder &_fbb, const " +
|
||||
return "::flatbuffers::Offset<" + Name(struct_def) + "> Create" +
|
||||
Name(struct_def) +
|
||||
"(::flatbuffers::FlatBufferBuilder &_fbb, const " +
|
||||
NativeName(Name(struct_def), &struct_def, opts) +
|
||||
" *_o, const flatbuffers::rehasher_function_t *_rehasher" +
|
||||
" *_o, const ::flatbuffers::rehasher_function_t *_rehasher" +
|
||||
(predecl ? " = nullptr" : "") + ")";
|
||||
}
|
||||
|
||||
std::string TablePackSignature(const StructDef &struct_def, bool inclass,
|
||||
const IDLOptions &opts) {
|
||||
return std::string(inclass ? "static " : "") + "flatbuffers::Offset<" +
|
||||
return std::string(inclass ? "static " : "") + "::flatbuffers::Offset<" +
|
||||
Name(struct_def) + "> " + (inclass ? "" : Name(struct_def) + "::") +
|
||||
"Pack(flatbuffers::FlatBufferBuilder &_fbb, " + "const " +
|
||||
"Pack(::flatbuffers::FlatBufferBuilder &_fbb, " + "const " +
|
||||
NativeName(Name(struct_def), &struct_def, opts) + "* _o, " +
|
||||
"const flatbuffers::rehasher_function_t *_rehasher" +
|
||||
"const ::flatbuffers::rehasher_function_t *_rehasher" +
|
||||
(inclass ? " = nullptr" : "") + ")";
|
||||
}
|
||||
|
||||
@@ -1032,7 +1039,7 @@ class CppGenerator : public BaseGenerator {
|
||||
const IDLOptions &opts) {
|
||||
return NativeName(Name(struct_def), &struct_def, opts) + " *" +
|
||||
(inclass ? "" : Name(struct_def) + "::") +
|
||||
"UnPack(const flatbuffers::resolver_function_t *_resolver" +
|
||||
"UnPack(const ::flatbuffers::resolver_function_t *_resolver" +
|
||||
(inclass ? " = nullptr" : "") + ") const";
|
||||
}
|
||||
|
||||
@@ -1040,13 +1047,13 @@ class CppGenerator : public BaseGenerator {
|
||||
const IDLOptions &opts) {
|
||||
return "void " + (inclass ? "" : Name(struct_def) + "::") + "UnPackTo(" +
|
||||
NativeName(Name(struct_def), &struct_def, opts) + " *" +
|
||||
"_o, const flatbuffers::resolver_function_t *_resolver" +
|
||||
"_o, const ::flatbuffers::resolver_function_t *_resolver" +
|
||||
(inclass ? " = nullptr" : "") + ") const";
|
||||
}
|
||||
|
||||
void GenMiniReflectPre(const StructDef *struct_def) {
|
||||
code_.SetValue("NAME", struct_def->name);
|
||||
code_ += "inline const flatbuffers::TypeTable *{{NAME}}TypeTable();";
|
||||
code_ += "inline const ::flatbuffers::TypeTable *{{NAME}}TypeTable();";
|
||||
code_ += "";
|
||||
}
|
||||
|
||||
@@ -1104,9 +1111,9 @@ class CppGenerator : public BaseGenerator {
|
||||
}
|
||||
}
|
||||
if (is_array) { array_sizes.push_back(type.fixed_length); }
|
||||
ts += "{ flatbuffers::" + std::string(ElementaryTypeNames()[et]) + ", " +
|
||||
NumToString(is_vector || is_array) + ", " + NumToString(ref_idx) +
|
||||
" }";
|
||||
ts += "{ ::flatbuffers::" + std::string(ElementaryTypeNames()[et]) +
|
||||
", " + NumToString(is_vector || is_array) + ", " +
|
||||
NumToString(ref_idx) + " }";
|
||||
}
|
||||
std::string rs;
|
||||
for (auto &type_ref : type_refs) {
|
||||
@@ -1147,14 +1154,14 @@ class CppGenerator : public BaseGenerator {
|
||||
code_.SetValue("ARRAYSIZES", as);
|
||||
code_.SetValue("NAMES", ns);
|
||||
code_.SetValue("VALUES", vs);
|
||||
code_ += "inline const flatbuffers::TypeTable *{{NAME}}TypeTable() {";
|
||||
code_ += "inline const ::flatbuffers::TypeTable *{{NAME}}TypeTable() {";
|
||||
if (num_fields) {
|
||||
code_ += " static const flatbuffers::TypeCode type_codes[] = {";
|
||||
code_ += " static const ::flatbuffers::TypeCode type_codes[] = {";
|
||||
code_ += " {{TYPES}}";
|
||||
code_ += " };";
|
||||
}
|
||||
if (!type_refs.empty()) {
|
||||
code_ += " static const flatbuffers::TypeFunction type_refs[] = {";
|
||||
code_ += " static const ::flatbuffers::TypeFunction type_refs[] = {";
|
||||
code_ += " {{REFS}}";
|
||||
code_ += " };";
|
||||
}
|
||||
@@ -1172,8 +1179,8 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ += " {{NAMES}}";
|
||||
code_ += " };";
|
||||
}
|
||||
code_ += " static const flatbuffers::TypeTable tt = {";
|
||||
code_ += std::string(" flatbuffers::{{SEQ_TYPE}}, {{NUM_FIELDS}}, ") +
|
||||
code_ += " static const ::flatbuffers::TypeTable tt = {";
|
||||
code_ += std::string(" ::flatbuffers::{{SEQ_TYPE}}, {{NUM_FIELDS}}, ") +
|
||||
(num_fields ? "type_codes, " : "nullptr, ") +
|
||||
(!type_refs.empty() ? "type_refs, " : "nullptr, ") +
|
||||
(!as.empty() ? "array_sizes, " : "nullptr, ") +
|
||||
@@ -1223,6 +1230,8 @@ class CppGenerator : public BaseGenerator {
|
||||
FLATBUFFERS_ASSERT(minv && maxv);
|
||||
|
||||
code_.SetValue("SEP", ",\n");
|
||||
|
||||
// MIN & MAX are useless for bit_flags
|
||||
if (enum_def.attributes.Lookup("bit_flags")) {
|
||||
code_.SetValue("KEY", GenEnumValDecl(enum_def, "NONE"));
|
||||
code_.SetValue("VALUE", "0");
|
||||
@@ -1233,7 +1242,7 @@ class CppGenerator : public BaseGenerator {
|
||||
NumToStringCpp(enum_def.AllFlags(),
|
||||
enum_def.underlying_type.base_type));
|
||||
code_ += "{{SEP}} {{KEY}} = {{VALUE}}\\";
|
||||
} else { // MIN & MAX are useless for bit_flags
|
||||
} else if (opts_.emit_min_max_enum_values) {
|
||||
code_.SetValue("KEY", GenEnumValDecl(enum_def, "MIN"));
|
||||
code_.SetValue("VALUE", GenEnumValDecl(enum_def, Name(*minv)));
|
||||
code_ += "{{SEP}} {{KEY}} = {{VALUE}}\\";
|
||||
@@ -1381,7 +1390,7 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ += " if (lhs.type != rhs.type) return false;";
|
||||
code_ += " switch (lhs.type) {";
|
||||
|
||||
for (const auto &ev: enum_def.Vals()) {
|
||||
for (const auto &ev : enum_def.Vals()) {
|
||||
code_.SetValue("NATIVE_ID", GetEnumValUse(enum_def, *ev));
|
||||
if (ev->IsNonZero()) {
|
||||
const auto native_type = GetUnionElement(*ev, true, opts_);
|
||||
@@ -1465,7 +1474,7 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
code_ += "inline const char *EnumName{{ENUM_NAME}}({{ENUM_NAME}} e) {";
|
||||
|
||||
code_ += " if (flatbuffers::IsOutRange(e, " +
|
||||
code_ += " if (::flatbuffers::IsOutRange(e, " +
|
||||
GetEnumValUse(enum_def, *enum_def.MinValue()) + ", " +
|
||||
GetEnumValUse(enum_def, *enum_def.MaxValue()) +
|
||||
")) return \"\";";
|
||||
@@ -1545,7 +1554,8 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ += "inline " + UnionVectorVerifySignature(enum_def) + " {";
|
||||
code_ += " if (!values || !types) return !values && !types;";
|
||||
code_ += " if (values->size() != types->size()) return false;";
|
||||
code_ += " for (flatbuffers::uoffset_t i = 0; i < values->size(); ++i) {";
|
||||
code_ +=
|
||||
" for (::flatbuffers::uoffset_t i = 0; i < values->size(); ++i) {";
|
||||
code_ += " if (!Verify" + Name(enum_def) + "(";
|
||||
code_ += " verifier, values->Get(i), types->GetEnum<" +
|
||||
Name(enum_def) + ">(i))) {";
|
||||
@@ -1626,7 +1636,7 @@ class CppGenerator : public BaseGenerator {
|
||||
"inline {{ENUM_NAME}}Union::{{ENUM_NAME}}Union(const "
|
||||
"{{ENUM_NAME}}Union &u) : type(u.type), value(nullptr) {";
|
||||
code_ += " switch (type) {";
|
||||
for (const auto &ev: enum_def.Vals()) {
|
||||
for (const auto &ev : enum_def.Vals()) {
|
||||
if (ev->IsZero()) { continue; }
|
||||
code_.SetValue("LABEL", GetEnumValUse(enum_def, *ev));
|
||||
code_.SetValue("TYPE", GetUnionElement(*ev, true, opts_));
|
||||
@@ -1942,7 +1952,7 @@ class CppGenerator : public BaseGenerator {
|
||||
std::string initializer_list;
|
||||
std::string vector_copies;
|
||||
std::string swaps;
|
||||
for (const auto &field: struct_def.fields.vec) {
|
||||
for (const auto &field : struct_def.fields.vec) {
|
||||
const auto &type = field->value.type;
|
||||
if (field->deprecated || type.base_type == BASE_TYPE_UTYPE) continue;
|
||||
if (type.base_type == BASE_TYPE_STRUCT) {
|
||||
@@ -2036,7 +2046,7 @@ class CppGenerator : public BaseGenerator {
|
||||
}
|
||||
|
||||
void GenCompareOperator(const StructDef &struct_def,
|
||||
const std::string& accessSuffix = "") {
|
||||
const std::string &accessSuffix = "") {
|
||||
std::string compare_op;
|
||||
for (auto it = struct_def.fields.vec.begin();
|
||||
it != struct_def.fields.vec.end(); ++it) {
|
||||
@@ -2044,7 +2054,6 @@ class CppGenerator : public BaseGenerator {
|
||||
const auto accessor = Name(field) + accessSuffix;
|
||||
const auto lhs_accessor = "lhs." + accessor;
|
||||
const auto rhs_accessor = "rhs." + accessor;
|
||||
|
||||
if (!field.deprecated && // Deprecated fields won't be accessible.
|
||||
field.value.type.base_type != BASE_TYPE_UTYPE &&
|
||||
(field.value.type.base_type != BASE_TYPE_VECTOR ||
|
||||
@@ -2067,6 +2076,8 @@ class CppGenerator : public BaseGenerator {
|
||||
" const &b) { return (a == b) || (a && b && *a == *b); })";
|
||||
|
||||
compare_op += "(" + equal_length + " && " + elements_equal + ")";
|
||||
} else if (field.value.type.base_type == BASE_TYPE_ARRAY) {
|
||||
compare_op += "(*" + lhs_accessor + " == *" + rhs_accessor + ")";
|
||||
} else {
|
||||
compare_op += "(" + lhs_accessor + " == " + rhs_accessor + ")";
|
||||
}
|
||||
@@ -2134,12 +2145,10 @@ class CppGenerator : public BaseGenerator {
|
||||
code_.SetValue("NATIVE_NAME", native_name);
|
||||
|
||||
// Generate a C++ object that can hold an unpacked version of this table.
|
||||
code_ += "struct {{NATIVE_NAME}} : public flatbuffers::NativeTable {";
|
||||
code_ += "struct {{NATIVE_NAME}} : public ::flatbuffers::NativeTable {";
|
||||
code_ += " typedef {{STRUCT_NAME}} TableType;";
|
||||
GenFullyQualifiedNameGetter(struct_def, native_name);
|
||||
for (const auto field : struct_def.fields.vec) {
|
||||
GenMember(*field);
|
||||
}
|
||||
for (const auto field : struct_def.fields.vec) { GenMember(*field); }
|
||||
GenOperatorNewDelete(struct_def);
|
||||
GenDefaultConstructor(struct_def);
|
||||
GenCopyMoveCtorAndAssigOpDecls(struct_def);
|
||||
@@ -2245,7 +2254,7 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ +=
|
||||
" bool KeyCompareLessThan(const {{STRUCT_NAME}} * const o) const {";
|
||||
if (is_string) {
|
||||
// use operator< of flatbuffers::String
|
||||
// use operator< of ::flatbuffers::String
|
||||
code_ += " return *{{FIELD_NAME}}() < *o->{{FIELD_NAME}}();";
|
||||
} else if (is_array) {
|
||||
const auto &elem_type = field.value.type.VectorType();
|
||||
@@ -2263,7 +2272,7 @@ class CppGenerator : public BaseGenerator {
|
||||
} else if (is_array) {
|
||||
const auto &elem_type = field.value.type.VectorType();
|
||||
if (IsScalar(elem_type.base_type)) {
|
||||
std::string input_type = "flatbuffers::Array<" +
|
||||
std::string input_type = "::flatbuffers::Array<" +
|
||||
GenTypeBasic(elem_type, false) + ", " +
|
||||
NumToString(elem_type.fixed_length) + ">";
|
||||
code_.SetValue("INPUT_TYPE", input_type);
|
||||
@@ -2273,7 +2282,7 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ +=
|
||||
" const {{INPUT_TYPE}} *curr_{{FIELD_NAME}} = {{FIELD_NAME}}();";
|
||||
code_ +=
|
||||
" for (flatbuffers::uoffset_t i = 0; i < "
|
||||
" for (::flatbuffers::uoffset_t i = 0; i < "
|
||||
"curr_{{FIELD_NAME}}->size(); i++) {";
|
||||
code_ += " const auto lhs = curr_{{FIELD_NAME}}->Get(i);";
|
||||
code_ += " const auto rhs = _{{FIELD_NAME}}->Get(i);";
|
||||
@@ -2578,7 +2587,7 @@ class CppGenerator : public BaseGenerator {
|
||||
code_.SetValue("STRUCT_NAME", Name(struct_def));
|
||||
code_ +=
|
||||
"struct {{STRUCT_NAME}} FLATBUFFERS_FINAL_CLASS"
|
||||
" : private flatbuffers::Table {";
|
||||
" : private ::flatbuffers::Table {";
|
||||
if (opts_.generate_object_based_api) {
|
||||
code_ += " typedef {{NATIVE_NAME}} NativeTableType;";
|
||||
}
|
||||
@@ -2586,7 +2595,7 @@ class CppGenerator : public BaseGenerator {
|
||||
if (opts_.g_cpp_std >= cpp::CPP_STD_17) { code_ += " struct Traits;"; }
|
||||
if (opts_.mini_reflect != IDLOptions::kNone) {
|
||||
code_ +=
|
||||
" static const flatbuffers::TypeTable *MiniReflectTypeTable() {";
|
||||
" static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {";
|
||||
code_ += " return {{STRUCT_NAME}}TypeTable();";
|
||||
code_ += " }";
|
||||
}
|
||||
@@ -2632,7 +2641,7 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ += " const {{CPP_NAME}} *{{FIELD_NAME}}_nested_root() const {";
|
||||
code_ +=
|
||||
" return "
|
||||
"flatbuffers::GetRoot<{{CPP_NAME}}>({{FIELD_NAME}}()->Data());";
|
||||
"::flatbuffers::GetRoot<{{CPP_NAME}}>({{FIELD_NAME}}()->Data());";
|
||||
code_ += " }";
|
||||
}
|
||||
|
||||
@@ -2656,7 +2665,7 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
// Generate a verifier function that can check a buffer from an untrusted
|
||||
// source will never cause reads outside the buffer.
|
||||
code_ += " bool Verify(flatbuffers::Verifier &verifier) const {";
|
||||
code_ += " bool Verify(::flatbuffers::Verifier &verifier) const {";
|
||||
code_ += " return VerifyTableStart(verifier)\\";
|
||||
for (const auto &field : struct_def.fields.vec) {
|
||||
if (field->deprecated) { continue; }
|
||||
@@ -2746,8 +2755,8 @@ class CppGenerator : public BaseGenerator {
|
||||
// Generate a builder struct:
|
||||
code_ += "struct {{STRUCT_NAME}}Builder {";
|
||||
code_ += " typedef {{STRUCT_NAME}} Table;";
|
||||
code_ += " flatbuffers::FlatBufferBuilder &fbb_;";
|
||||
code_ += " flatbuffers::uoffset_t start_;";
|
||||
code_ += " ::flatbuffers::FlatBufferBuilder &fbb_;";
|
||||
code_ += " ::flatbuffers::uoffset_t start_;";
|
||||
|
||||
bool has_string_or_vector_fields = false;
|
||||
for (auto it = struct_def.fields.vec.begin();
|
||||
@@ -2794,18 +2803,18 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
// Builder constructor
|
||||
code_ +=
|
||||
" explicit {{STRUCT_NAME}}Builder(flatbuffers::FlatBufferBuilder "
|
||||
" explicit {{STRUCT_NAME}}Builder(::flatbuffers::FlatBufferBuilder "
|
||||
"&_fbb)";
|
||||
code_ += " : fbb_(_fbb) {";
|
||||
code_ += " start_ = fbb_.StartTable();";
|
||||
code_ += " }";
|
||||
|
||||
// Finish() function.
|
||||
code_ += " flatbuffers::Offset<{{STRUCT_NAME}}> Finish() {";
|
||||
code_ += " ::flatbuffers::Offset<{{STRUCT_NAME}}> Finish() {";
|
||||
code_ += " const auto end = fbb_.EndTable(start_);";
|
||||
code_ += " auto o = flatbuffers::Offset<{{STRUCT_NAME}}>(end);";
|
||||
code_ += " auto o = ::flatbuffers::Offset<{{STRUCT_NAME}}>(end);";
|
||||
|
||||
for (const auto &field: struct_def.fields.vec) {
|
||||
for (const auto &field : struct_def.fields.vec) {
|
||||
if (!field->deprecated && field->IsRequired()) {
|
||||
code_.SetValue("FIELD_NAME", Name(*field));
|
||||
code_.SetValue("OFFSET_NAME", GenFieldOffsetName(*field));
|
||||
@@ -2820,13 +2829,11 @@ class CppGenerator : public BaseGenerator {
|
||||
// Generate a convenient CreateX function that uses the above builder
|
||||
// to create a table in one go.
|
||||
code_ +=
|
||||
"inline flatbuffers::Offset<{{STRUCT_NAME}}> "
|
||||
"inline ::flatbuffers::Offset<{{STRUCT_NAME}}> "
|
||||
"Create{{STRUCT_NAME}}(";
|
||||
code_ += " flatbuffers::FlatBufferBuilder &_fbb\\";
|
||||
code_ += " ::flatbuffers::FlatBufferBuilder &_fbb\\";
|
||||
for (const auto &field : struct_def.fields.vec) {
|
||||
if (!field->deprecated) {
|
||||
GenParam(*field, false, ",\n ");
|
||||
}
|
||||
if (!field->deprecated) { GenParam(*field, false, ",\n "); }
|
||||
}
|
||||
code_ += ") {";
|
||||
|
||||
@@ -2860,9 +2867,9 @@ class CppGenerator : public BaseGenerator {
|
||||
// Generate a CreateXDirect function with vector types as parameters
|
||||
if (opts_.cpp_direct_copy && has_string_or_vector_fields) {
|
||||
code_ +=
|
||||
"inline flatbuffers::Offset<{{STRUCT_NAME}}> "
|
||||
"inline ::flatbuffers::Offset<{{STRUCT_NAME}}> "
|
||||
"Create{{STRUCT_NAME}}Direct(";
|
||||
code_ += " flatbuffers::FlatBufferBuilder &_fbb\\";
|
||||
code_ += " ::flatbuffers::FlatBufferBuilder &_fbb\\";
|
||||
for (const auto &field : struct_def.fields.vec) {
|
||||
if (!field->deprecated) { GenParam(*field, true, ",\n "); }
|
||||
}
|
||||
@@ -2952,7 +2959,7 @@ class CppGenerator : public BaseGenerator {
|
||||
const auto &struct_attrs = type.struct_def->attributes;
|
||||
const auto native_type = struct_attrs.Lookup("native_type");
|
||||
if (native_type) {
|
||||
std::string unpack_call = "flatbuffers::UnPack";
|
||||
std::string unpack_call = "::flatbuffers::UnPack";
|
||||
const auto pack_name = struct_attrs.Lookup("native_type_pack_name");
|
||||
if (pack_name) { unpack_call += pack_name->constant; }
|
||||
unpack_call += "(*" + val + ")";
|
||||
@@ -3026,7 +3033,7 @@ class CppGenerator : public BaseGenerator {
|
||||
: (field.value.type.element == BASE_TYPE_UNION ? ".value"
|
||||
: "");
|
||||
|
||||
code += "for (flatbuffers::uoffset_t _i = 0;";
|
||||
code += "for (::flatbuffers::uoffset_t _i = 0;";
|
||||
code += " _i < _e->size(); _i++) { ";
|
||||
auto cpp_type = field.attributes.Lookup("cpp_type");
|
||||
if (cpp_type) {
|
||||
@@ -3041,7 +3048,7 @@ class CppGenerator : public BaseGenerator {
|
||||
code += "(reinterpret_cast<void **>(&_o->" + name + "[_i]" +
|
||||
access + "), ";
|
||||
code +=
|
||||
"static_cast<flatbuffers::hash_value_t>(" + indexing + "));";
|
||||
"static_cast<::flatbuffers::hash_value_t>(" + indexing + "));";
|
||||
if (PtrType(&field) == "naked") {
|
||||
code += " else ";
|
||||
code += "_o->" + name + "[_i]" + access + " = nullptr";
|
||||
@@ -3096,7 +3103,7 @@ class CppGenerator : public BaseGenerator {
|
||||
code += "if (_resolver) ";
|
||||
code += "(*_resolver)";
|
||||
code += "(reinterpret_cast<void **>(&_o->" + Name(field) + "), ";
|
||||
code += "static_cast<flatbuffers::hash_value_t>(_e));";
|
||||
code += "static_cast<::flatbuffers::hash_value_t>(_e));";
|
||||
if (PtrType(&field) == "naked") {
|
||||
code += " else ";
|
||||
code += "_o->" + Name(field) + " = nullptr;";
|
||||
@@ -3193,7 +3200,8 @@ class CppGenerator : public BaseGenerator {
|
||||
// Use by-function serialization to emulate
|
||||
// CreateVectorOfStrings(); this works also with non-std strings.
|
||||
code +=
|
||||
"_fbb.CreateVector<flatbuffers::Offset<flatbuffers::String>>"
|
||||
"_fbb.CreateVector<::flatbuffers::Offset<::flatbuffers::"
|
||||
"String>>"
|
||||
" ";
|
||||
code += "(" + value + ".size(), ";
|
||||
code += "[](size_t i, _VectorArgs *__va) { ";
|
||||
@@ -3216,7 +3224,7 @@ class CppGenerator : public BaseGenerator {
|
||||
const auto pack_name =
|
||||
struct_attrs.Lookup("native_type_pack_name");
|
||||
if (pack_name) {
|
||||
code += ", flatbuffers::Pack" + pack_name->constant;
|
||||
code += ", ::flatbuffers::Pack" + pack_name->constant;
|
||||
}
|
||||
code += ")";
|
||||
} else {
|
||||
@@ -3224,7 +3232,7 @@ class CppGenerator : public BaseGenerator {
|
||||
code += "(" + value + ")";
|
||||
}
|
||||
} else {
|
||||
code += "_fbb.CreateVector<flatbuffers::Offset<";
|
||||
code += "_fbb.CreateVector<::flatbuffers::Offset<";
|
||||
code += WrapInNameSpace(*vector_type.struct_def) + ">> ";
|
||||
code += "(" + value + ".size(), ";
|
||||
code += "[](size_t i, _VectorArgs *__va) { ";
|
||||
@@ -3245,7 +3253,7 @@ class CppGenerator : public BaseGenerator {
|
||||
}
|
||||
case BASE_TYPE_UNION: {
|
||||
code +=
|
||||
"_fbb.CreateVector<flatbuffers::"
|
||||
"_fbb.CreateVector<::flatbuffers::"
|
||||
"Offset<void>>(" +
|
||||
value +
|
||||
".size(), [](size_t i, _VectorArgs *__va) { "
|
||||
@@ -3274,7 +3282,7 @@ class CppGenerator : public BaseGenerator {
|
||||
const auto basetype = GenTypeBasic(
|
||||
field.value.type.enum_def->underlying_type, false);
|
||||
code += "_fbb.CreateVectorScalarCast<" + basetype +
|
||||
">(flatbuffers::data(" + value + "), " + value +
|
||||
">(::flatbuffers::data(" + value + "), " + value +
|
||||
".size())";
|
||||
} else if (field.attributes.Lookup("cpp_type")) {
|
||||
auto type = GenTypeBasic(vector_type, false);
|
||||
@@ -3310,7 +3318,7 @@ class CppGenerator : public BaseGenerator {
|
||||
const auto &struct_attribs = field.value.type.struct_def->attributes;
|
||||
const auto native_type = struct_attribs.Lookup("native_type");
|
||||
if (native_type) {
|
||||
code += "flatbuffers::Pack";
|
||||
code += "::flatbuffers::Pack";
|
||||
const auto pack_name =
|
||||
struct_attribs.Lookup("native_type_pack_name");
|
||||
if (pack_name) { code += pack_name->constant; }
|
||||
@@ -3412,11 +3420,11 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
code_ +=
|
||||
" struct _VectorArgs "
|
||||
"{ flatbuffers::FlatBufferBuilder *__fbb; "
|
||||
"{ ::flatbuffers::FlatBufferBuilder *__fbb; "
|
||||
"const " +
|
||||
NativeName(Name(struct_def), &struct_def, opts_) +
|
||||
"* __o; "
|
||||
"const flatbuffers::rehasher_function_t *__rehasher; } _va = { "
|
||||
"const ::flatbuffers::rehasher_function_t *__rehasher; } _va = { "
|
||||
"&_fbb, _o, _rehasher}; (void)_va;";
|
||||
|
||||
for (auto it = struct_def.fields.vec.begin();
|
||||
@@ -3565,7 +3573,7 @@ class CppGenerator : public BaseGenerator {
|
||||
init_list += Name(field) + "_";
|
||||
if (IsScalar(type.base_type)) {
|
||||
auto scalar_type = GenUnderlyingCast(field, false, arg_name);
|
||||
init_list += "(flatbuffers::EndianScalar(" + scalar_type + "))";
|
||||
init_list += "(::flatbuffers::EndianScalar(" + scalar_type + "))";
|
||||
} else {
|
||||
FLATBUFFERS_ASSERT((is_array && !init_arrays) || IsStruct(type));
|
||||
if (!is_array)
|
||||
@@ -3601,7 +3609,7 @@ class CppGenerator : public BaseGenerator {
|
||||
is_enum ? "CastToArrayOfEnum<" + face_type + ">" : "CastToArray";
|
||||
const auto field_name = Name(*field) + "_";
|
||||
const auto arg_name = "_" + Name(*field);
|
||||
code_ += " flatbuffers::" + get_array + "(" + field_name +
|
||||
code_ += " ::flatbuffers::" + get_array + "(" + field_name +
|
||||
").CopyFromSpan(" + arg_name + ");";
|
||||
}
|
||||
if (field->padding) {
|
||||
@@ -3621,7 +3629,7 @@ class CppGenerator : public BaseGenerator {
|
||||
// It requires a specialization of Array class.
|
||||
// Generate Array<uint8_t> for Array<bool>.
|
||||
const auto face_type = GenTypeGet(type, " ", "", "", is_enum);
|
||||
std::string ret_type = "flatbuffers::Array<" + face_type + ", " +
|
||||
std::string ret_type = "::flatbuffers::Array<" + face_type + ", " +
|
||||
NumToString(type.fixed_length) + ">";
|
||||
if (mutable_accessor)
|
||||
code_ += " " + ret_type + " *mutable_{{FIELD_NAME}}() {";
|
||||
@@ -3630,7 +3638,7 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
std::string get_array =
|
||||
is_enum ? "CastToArrayOfEnum<" + face_type + ">" : "CastToArray";
|
||||
code_ += " return &flatbuffers::" + get_array + "({{FIELD_VALUE}});";
|
||||
code_ += " return &::flatbuffers::" + get_array + "({{FIELD_VALUE}});";
|
||||
code_ += " }";
|
||||
}
|
||||
|
||||
@@ -3651,7 +3659,7 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ += " private:";
|
||||
|
||||
int padding_id = 0;
|
||||
for (const auto &field: struct_def.fields.vec) {
|
||||
for (const auto &field : struct_def.fields.vec) {
|
||||
const auto &field_type = field->value.type;
|
||||
code_.SetValue("FIELD_TYPE", GenTypeGet(field_type, " ", "", " ", false));
|
||||
code_.SetValue("FIELD_NAME", Name(*field));
|
||||
@@ -3677,7 +3685,7 @@ class CppGenerator : public BaseGenerator {
|
||||
// Make TypeTable accessible via the generated struct.
|
||||
if (opts_.mini_reflect != IDLOptions::kNone) {
|
||||
code_ +=
|
||||
" static const flatbuffers::TypeTable *MiniReflectTypeTable() {";
|
||||
" static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {";
|
||||
code_ += " return {{STRUCT_NAME}}TypeTable();";
|
||||
code_ += " }";
|
||||
}
|
||||
@@ -3691,17 +3699,15 @@ class CppGenerator : public BaseGenerator {
|
||||
// excluding arrays.
|
||||
GenStructConstructor(struct_def, kArrayArgModeNone);
|
||||
|
||||
auto arrays_num = std::count_if(struct_def.fields.vec.begin(),
|
||||
struct_def.fields.vec.end(),
|
||||
[](const flatbuffers::FieldDef *fd) {
|
||||
return IsArray(fd->value.type);
|
||||
});
|
||||
auto arrays_num = std::count_if(
|
||||
struct_def.fields.vec.begin(), struct_def.fields.vec.end(),
|
||||
[](const FieldDef *fd) { return IsArray(fd->value.type); });
|
||||
if (arrays_num > 0) {
|
||||
GenStructConstructor(struct_def, kArrayArgModeSpanStatic);
|
||||
}
|
||||
|
||||
// Generate accessor methods of the form:
|
||||
// type name() const { return flatbuffers::EndianScalar(name_); }
|
||||
// type name() const { return ::flatbuffers::EndianScalar(name_); }
|
||||
for (const auto &field : struct_def.fields.vec) {
|
||||
const auto &type = field->value.type;
|
||||
const auto is_scalar = IsScalar(type.base_type);
|
||||
@@ -3711,7 +3717,7 @@ class CppGenerator : public BaseGenerator {
|
||||
is_array ? "" : " &", true);
|
||||
auto member = Name(*field) + "_";
|
||||
auto value =
|
||||
is_scalar ? "flatbuffers::EndianScalar(" + member + ")" : member;
|
||||
is_scalar ? "::flatbuffers::EndianScalar(" + member + ")" : member;
|
||||
|
||||
code_.SetValue("FIELD_NAME", Name(*field));
|
||||
code_.SetValue("FIELD_TYPE", field_type);
|
||||
@@ -3740,7 +3746,7 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
code_ += " void mutate_{{FIELD_NAME}}({{ARG}} _{{FIELD_NAME}}) {";
|
||||
code_ +=
|
||||
" flatbuffers::WriteScalar(&{{FIELD_NAME}}_, "
|
||||
" ::flatbuffers::WriteScalar(&{{FIELD_NAME}}_, "
|
||||
"{{FIELD_VALUE}});";
|
||||
code_ += " }";
|
||||
} else if (is_array) {
|
||||
@@ -3855,8 +3861,7 @@ bool GenerateCPP(const Parser &parser, const std::string &path,
|
||||
|
||||
std::string CPPMakeRule(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name) {
|
||||
const auto filebase =
|
||||
flatbuffers::StripPath(flatbuffers::StripExtension(file_name));
|
||||
const auto filebase = StripPath(StripExtension(file_name));
|
||||
cpp::CppGenerator geneartor(parser, path, file_name, parser.opts);
|
||||
const auto included_files = parser.GetIncludedFilesRecursive(file_name);
|
||||
std::string make_rule =
|
||||
@@ -3867,4 +3872,50 @@ std::string CPPMakeRule(const Parser &parser, const std::string &path,
|
||||
return make_rule;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class CppCodeGenerator : public CodeGenerator {
|
||||
public:
|
||||
Status GenerateCode(const Parser &parser, const std::string &path,
|
||||
const std::string &filename) override {
|
||||
if (!GenerateCPP(parser, path, filename)) { return Status::ERROR; }
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
// Generate code from the provided `buffer` of given `length`. The buffer is a
|
||||
// serialized reflection.fbs.
|
||||
Status GenerateCode(const uint8_t *buffer, int64_t length) override {
|
||||
(void) buffer;
|
||||
(void) length;
|
||||
return Status::NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
Status GenerateMakeRule(const Parser &parser, const std::string &path,
|
||||
const std::string &filename,
|
||||
std::string &output) override {
|
||||
output = CPPMakeRule(parser, path, filename);
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
Status GenerateGrpcCode(const Parser &parser, const std::string &path,
|
||||
const std::string &filename) override {
|
||||
if (!GenerateCppGRPC(parser, path, filename)) { return Status::ERROR; }
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
bool IsSchemaOnly() const override { return true; }
|
||||
|
||||
bool SupportsBfbsGeneration() const override { return false; }
|
||||
|
||||
IDLOptions::Language Language() const override { return IDLOptions::kCpp; }
|
||||
|
||||
std::string LanguageName() const override { return "C++"; }
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<CodeGenerator> NewCppCodeGenerator() {
|
||||
return std::unique_ptr<CppCodeGenerator>(new CppCodeGenerator());
|
||||
}
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
@@ -655,7 +655,7 @@ class CSharpGenerator : public BaseGenerator {
|
||||
// Force compile time error if not using the same version runtime.
|
||||
code += " public static void ValidateVersion() {";
|
||||
code += " FlatBufferConstants.";
|
||||
code += "FLATBUFFERS_23_1_4(); ";
|
||||
code += "FLATBUFFERS_23_1_21(); ";
|
||||
code += "}\n";
|
||||
|
||||
// Generate a special accessor for the table that when used as the root
|
||||
@@ -1525,7 +1525,7 @@ class CSharpGenerator : public BaseGenerator {
|
||||
" _o, "
|
||||
"Newtonsoft.Json.JsonSerializer serializer) {\n";
|
||||
code += " if (_o == null) return;\n";
|
||||
code += " serializer.Serialize(writer, _o.Value);\n";
|
||||
code += " serializer.Serialize(writer, _o." + class_member + ");\n";
|
||||
code += " }\n";
|
||||
code +=
|
||||
" public override object ReadJson(Newtonsoft.Json.JsonReader "
|
||||
@@ -1562,8 +1562,8 @@ class CSharpGenerator : public BaseGenerator {
|
||||
code += " default: break;\n";
|
||||
} else {
|
||||
auto type_name = GenTypeGet_ObjectAPI(ev.union_type, opts);
|
||||
code += " case " + Name(enum_def) + "." + Name(ev) +
|
||||
": _o.Value = serializer.Deserialize<" + type_name +
|
||||
code += " case " + Name(enum_def) + "." + Name(ev) + ": _o." +
|
||||
class_member + " = serializer.Deserialize<" + type_name +
|
||||
">(reader); break;\n";
|
||||
}
|
||||
}
|
||||
@@ -1586,7 +1586,7 @@ class CSharpGenerator : public BaseGenerator {
|
||||
auto &code = *code_ptr;
|
||||
std::string varialbe_name = "_o." + camel_name;
|
||||
std::string class_member = "Value";
|
||||
if (class_member == camel_name) class_member += "_";
|
||||
if (class_member == enum_def.name) class_member += "_";
|
||||
std::string type_suffix = "";
|
||||
std::string func_suffix = "()";
|
||||
std::string indent = " ";
|
||||
|
||||
@@ -683,7 +683,7 @@ class JavaGenerator : public BaseGenerator {
|
||||
// Force compile time error if not using the same version runtime.
|
||||
code += " public static void ValidateVersion() {";
|
||||
code += " Constants.";
|
||||
code += "FLATBUFFERS_23_1_4(); ";
|
||||
code += "FLATBUFFERS_23_1_21(); ";
|
||||
code += "}\n";
|
||||
|
||||
// Generate a special accessor for the table that when used as the root
|
||||
|
||||
@@ -132,9 +132,22 @@ class KotlinGenerator : public BaseGenerator {
|
||||
code += "\n\n";
|
||||
}
|
||||
if (needs_includes) {
|
||||
code += "import java.nio.*\n";
|
||||
code += "import kotlin.math.sign\n";
|
||||
code += "import com.google.flatbuffers.*\n\n";
|
||||
code +=
|
||||
"import com.google.flatbuffers.BaseVector\n"
|
||||
"import com.google.flatbuffers.BooleanVector\n"
|
||||
"import com.google.flatbuffers.ByteVector\n"
|
||||
"import com.google.flatbuffers.Constants\n"
|
||||
"import com.google.flatbuffers.DoubleVector\n"
|
||||
"import com.google.flatbuffers.FlatBufferBuilder\n"
|
||||
"import com.google.flatbuffers.FloatVector\n"
|
||||
"import com.google.flatbuffers.LongVector\n"
|
||||
"import com.google.flatbuffers.StringVector\n"
|
||||
"import com.google.flatbuffers.Struct\n"
|
||||
"import com.google.flatbuffers.Table\n"
|
||||
"import com.google.flatbuffers.UnionVector\n"
|
||||
"import java.nio.ByteBuffer\n"
|
||||
"import java.nio.ByteOrder\n"
|
||||
"import kotlin.math.sign\n\n";
|
||||
}
|
||||
code += classcode;
|
||||
const std::string dirs = namer_.Directories(ns);
|
||||
@@ -178,10 +191,11 @@ class KotlinGenerator : public BaseGenerator {
|
||||
auto r_type = GenTypeGet(field.value.type);
|
||||
if (field.IsScalarOptional() ||
|
||||
// string, structs and unions
|
||||
(base_type == BASE_TYPE_STRING || base_type == BASE_TYPE_STRUCT ||
|
||||
base_type == BASE_TYPE_UNION) ||
|
||||
(!field.IsRequired() &&
|
||||
(base_type == BASE_TYPE_STRING || base_type == BASE_TYPE_STRUCT ||
|
||||
base_type == BASE_TYPE_UNION)) ||
|
||||
// vector of anything not scalar
|
||||
(base_type == BASE_TYPE_VECTOR &&
|
||||
(base_type == BASE_TYPE_VECTOR && !field.IsRequired() &&
|
||||
!IsScalar(field.value.type.VectorType().base_type))) {
|
||||
r_type += "?";
|
||||
}
|
||||
@@ -273,6 +287,7 @@ class KotlinGenerator : public BaseGenerator {
|
||||
GenerateComment(enum_def.doc_comment, writer, &comment_config);
|
||||
|
||||
writer += "@Suppress(\"unused\")";
|
||||
writer += "@kotlin.ExperimentalUnsignedTypes";
|
||||
writer += "class " + namer_.Type(enum_def) + " private constructor() {";
|
||||
writer.IncrementIdentLevel();
|
||||
|
||||
@@ -299,7 +314,10 @@ class KotlinGenerator : public BaseGenerator {
|
||||
// Average distance between values above which we consider a table
|
||||
// "too sparse". Change at will.
|
||||
static const uint64_t kMaxSparseness = 5;
|
||||
if (range / static_cast<uint64_t>(enum_def.size()) < kMaxSparseness) {
|
||||
bool generate_names =
|
||||
range / static_cast<uint64_t>(enum_def.size()) < kMaxSparseness &&
|
||||
parser_.opts.mini_reflect == IDLOptions::kTypesAndNames;
|
||||
if (generate_names) {
|
||||
GeneratePropertyOneLine(writer, "names", "Array<String>", [&]() {
|
||||
writer += "arrayOf(\\";
|
||||
auto val = enum_def.Vals().front();
|
||||
@@ -475,6 +493,7 @@ class KotlinGenerator : public BaseGenerator {
|
||||
writer.SetValue("superclass", fixed ? "Struct" : "Table");
|
||||
|
||||
writer += "@Suppress(\"unused\")";
|
||||
writer += "@kotlin.ExperimentalUnsignedTypes";
|
||||
writer += "class {{struct_name}} : {{superclass}}() {\n";
|
||||
|
||||
writer.IncrementIdentLevel();
|
||||
@@ -505,7 +524,7 @@ class KotlinGenerator : public BaseGenerator {
|
||||
// runtime.
|
||||
GenerateFunOneLine(
|
||||
writer, "validateVersion", "", "",
|
||||
[&]() { writer += "Constants.FLATBUFFERS_23_1_4()"; },
|
||||
[&]() { writer += "Constants.FLATBUFFERS_23_1_21()"; },
|
||||
options.gen_jvmstatic);
|
||||
|
||||
GenerateGetRootAsAccessors(namer_.Type(struct_def), writer, options);
|
||||
@@ -985,7 +1004,15 @@ class KotlinGenerator : public BaseGenerator {
|
||||
OffsetWrapper(
|
||||
writer, offset_val,
|
||||
[&]() { writer += "obj.__assign({{seek}}, bb)"; },
|
||||
[&]() { writer += "null"; });
|
||||
[&]() {
|
||||
if (field.IsRequired()) {
|
||||
writer +=
|
||||
"throw AssertionError(\"No value for "
|
||||
"(required) field {{field_name}}\")";
|
||||
} else {
|
||||
writer += "null";
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
break;
|
||||
@@ -995,12 +1022,30 @@ class KotlinGenerator : public BaseGenerator {
|
||||
// val Name : String?
|
||||
// get() = {
|
||||
// val o = __offset(10)
|
||||
// return if (o != 0) __string(o + bb_pos) else null
|
||||
// return if (o != 0) {
|
||||
// __string(o + bb_pos)
|
||||
// } else {
|
||||
// null
|
||||
// }
|
||||
// }
|
||||
// ? adds nullability annotation
|
||||
GenerateGetter(writer, field_name, return_type, [&]() {
|
||||
writer += "val o = __offset({{offset}})";
|
||||
writer += "return if (o != 0) __string(o + bb_pos) else null";
|
||||
writer += "return if (o != 0) {";
|
||||
writer.IncrementIdentLevel();
|
||||
writer += "__string(o + bb_pos)";
|
||||
writer.DecrementIdentLevel();
|
||||
writer += "} else {";
|
||||
writer.IncrementIdentLevel();
|
||||
if (field.IsRequired()) {
|
||||
writer +=
|
||||
"throw AssertionError(\"No value for (required) field "
|
||||
"{{field_name}}\")";
|
||||
} else {
|
||||
writer += "null";
|
||||
}
|
||||
writer.DecrementIdentLevel();
|
||||
writer += "}";
|
||||
});
|
||||
break;
|
||||
case BASE_TYPE_VECTOR: {
|
||||
@@ -1025,7 +1070,11 @@ class KotlinGenerator : public BaseGenerator {
|
||||
GenerateFun(writer, field_name, params, return_type, [&]() {
|
||||
auto inline_size = NumToString(InlineSize(vectortype));
|
||||
auto index = "__vector(o) + j * " + inline_size;
|
||||
auto not_found = NotFoundReturn(field.value.type.element);
|
||||
auto not_found =
|
||||
field.IsRequired()
|
||||
? "throw IndexOutOfBoundsException(\"Index out of range: "
|
||||
"$j, vector {{field_name}} is empty\")"
|
||||
: NotFoundReturn(field.value.type.element);
|
||||
auto found = "";
|
||||
writer.SetValue("index", index);
|
||||
switch (vectortype.base_type) {
|
||||
|
||||
@@ -483,12 +483,6 @@ class SwiftGenerator : public BaseGenerator {
|
||||
"fileId: "
|
||||
"{{STRUCTNAME}}.id, addPrefix: prefix) }";
|
||||
}
|
||||
code_ +=
|
||||
"{{ACCESS_TYPE}} static func getRootAs{{SHORT_STRUCTNAME}}(bb: "
|
||||
"ByteBuffer) -> "
|
||||
"{{STRUCTNAME}} { return {{STRUCTNAME}}(Table(bb: bb, position: "
|
||||
"Int32(bb.read(def: UOffset.self, position: bb.reader)) + "
|
||||
"Int32(bb.reader))) }\n";
|
||||
code_ += "private init(_ t: Table) { {{ACCESS}} = t }";
|
||||
}
|
||||
code_ +=
|
||||
@@ -1846,7 +1840,7 @@ class SwiftGenerator : public BaseGenerator {
|
||||
}
|
||||
|
||||
std::string ValidateFunc() {
|
||||
return "static func validateVersion() { FlatBuffersVersion_23_1_4() }";
|
||||
return "static func validateVersion() { FlatBuffersVersion_23_1_21() }";
|
||||
}
|
||||
|
||||
std::string GenType(const Type &type,
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
@@ -39,6 +40,14 @@ struct ImportDefinition {
|
||||
const Definition *dependency = nullptr;
|
||||
};
|
||||
|
||||
struct NsDefinition {
|
||||
std::string path;
|
||||
std::string filepath;
|
||||
std::string symbolic_name;
|
||||
const Namespace *ns;
|
||||
std::map<std::string, const Definition *> definitions;
|
||||
};
|
||||
|
||||
Namer::Config TypeScriptDefaultConfig() {
|
||||
return { /*types=*/Case::kKeep,
|
||||
/*constants=*/Case::kUnknown,
|
||||
@@ -102,33 +111,26 @@ class TsGenerator : public BaseGenerator {
|
||||
generateEnums();
|
||||
generateStructs();
|
||||
generateEntry();
|
||||
if (!generateBundle()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IncludeNamespace() const {
|
||||
// When generating a single flat file and all its includes, namespaces are
|
||||
// important to avoid type name clashes.
|
||||
return parser_.opts.ts_flat_file && parser_.opts.generate_all;
|
||||
}
|
||||
|
||||
std::string GetTypeName(const EnumDef &def, const bool = false,
|
||||
const bool force_ns_wrap = false) {
|
||||
if (IncludeNamespace() || force_ns_wrap) {
|
||||
return namer_.NamespacedType(def);
|
||||
}
|
||||
if (force_ns_wrap) { return namer_.NamespacedType(def); }
|
||||
return namer_.Type(def);
|
||||
}
|
||||
|
||||
std::string GetTypeName(const StructDef &def, const bool object_api = false,
|
||||
const bool force_ns_wrap = false) {
|
||||
if (object_api && parser_.opts.generate_object_based_api) {
|
||||
if (IncludeNamespace() || force_ns_wrap) {
|
||||
if (force_ns_wrap) {
|
||||
return namer_.NamespacedObjectType(def);
|
||||
} else {
|
||||
return namer_.ObjectType(def);
|
||||
}
|
||||
} else {
|
||||
if (IncludeNamespace() || force_ns_wrap) {
|
||||
if (force_ns_wrap) {
|
||||
return namer_.NamespacedType(def);
|
||||
} else {
|
||||
return namer_.Type(def);
|
||||
@@ -144,58 +146,62 @@ class TsGenerator : public BaseGenerator {
|
||||
|
||||
std::string code;
|
||||
|
||||
if (!parser_.opts.ts_flat_file) {
|
||||
code += "// " + std::string(FlatBuffersGeneratedWarning()) + "\n\n";
|
||||
code += "// " + std::string(FlatBuffersGeneratedWarning()) + "\n\n";
|
||||
|
||||
for (auto it = bare_imports.begin(); it != bare_imports.end(); it++) {
|
||||
for (auto it = bare_imports.begin(); it != bare_imports.end(); it++) {
|
||||
code += it->second.import_statement + "\n";
|
||||
}
|
||||
if (!bare_imports.empty()) code += "\n";
|
||||
|
||||
for (auto it = imports.begin(); it != imports.end(); it++) {
|
||||
if (it->second.dependency != &definition) {
|
||||
code += it->second.import_statement + "\n";
|
||||
}
|
||||
if (!bare_imports.empty()) code += "\n";
|
||||
|
||||
for (auto it = imports.begin(); it != imports.end(); it++) {
|
||||
if (it->second.dependency != &definition) {
|
||||
code += it->second.import_statement + "\n";
|
||||
}
|
||||
}
|
||||
if (!imports.empty()) code += "\n\n";
|
||||
}
|
||||
if (!imports.empty()) code += "\n\n";
|
||||
|
||||
code += class_code;
|
||||
|
||||
if (parser_.opts.ts_flat_file) {
|
||||
flat_file_ += code;
|
||||
flat_file_ += "\n";
|
||||
flat_file_definitions_.insert(&definition);
|
||||
return true;
|
||||
} else {
|
||||
auto dirs = namer_.Directories(*definition.defined_namespace);
|
||||
EnsureDirExists(dirs);
|
||||
auto basename = dirs + namer_.File(definition, SkipFile::Suffix);
|
||||
auto dirs = namer_.Directories(*definition.defined_namespace);
|
||||
EnsureDirExists(dirs);
|
||||
auto basename = dirs + namer_.File(definition, SkipFile::Suffix);
|
||||
|
||||
return SaveFile(basename.c_str(), code, false);
|
||||
return SaveFile(basename.c_str(), code, false);
|
||||
}
|
||||
|
||||
void TrackNsDef(const Definition &definition, std::string type_name) {
|
||||
std::string path;
|
||||
std::string filepath;
|
||||
std::string symbolic_name;
|
||||
if (definition.defined_namespace->components.size() > 0) {
|
||||
path = namer_.Directories(*definition.defined_namespace,
|
||||
SkipDir::TrailingPathSeperator);
|
||||
filepath = path + ".ts";
|
||||
path = namer_.Directories(*definition.defined_namespace,
|
||||
SkipDir::OutputPathAndTrailingPathSeparator);
|
||||
symbolic_name = definition.defined_namespace->components.back();
|
||||
} else {
|
||||
auto def_mod_name = namer_.File(definition, SkipFile::SuffixAndExtension);
|
||||
symbolic_name = file_name_;
|
||||
filepath = path_ + symbolic_name + ".ts";
|
||||
}
|
||||
if (ns_defs_.count(path) == 0) {
|
||||
NsDefinition nsDef;
|
||||
nsDef.path = path;
|
||||
nsDef.filepath = filepath;
|
||||
nsDef.ns = definition.defined_namespace;
|
||||
nsDef.definitions.insert(std::make_pair(type_name, &definition));
|
||||
nsDef.symbolic_name = symbolic_name;
|
||||
ns_defs_[path] = nsDef;
|
||||
} else {
|
||||
ns_defs_[path].definitions.insert(std::make_pair(type_name, &definition));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
IdlNamer namer_;
|
||||
|
||||
import_set imports_all_;
|
||||
|
||||
// The following three members are used when generating typescript code into a
|
||||
// single file rather than creating separate files for each type.
|
||||
|
||||
// flat_file_ contains the aggregated contents of the file prior to being
|
||||
// written to disk.
|
||||
std::string flat_file_;
|
||||
// flat_file_definitions_ tracks which types have been written to flat_file_.
|
||||
std::unordered_set<const Definition *> flat_file_definitions_;
|
||||
// This maps from import names to types to import.
|
||||
std::map<std::string, std::map<std::string, std::string>>
|
||||
flat_file_import_declarations_;
|
||||
// For flat file codegen, tracks whether we need to import the flatbuffers
|
||||
// library itself (not necessary for files that solely consist of enum
|
||||
// definitions).
|
||||
bool import_flatbuffers_lib_ = false;
|
||||
std::map<std::string, NsDefinition> ns_defs_;
|
||||
|
||||
// Generate code for all enums.
|
||||
void generateEnums() {
|
||||
@@ -207,8 +213,9 @@ class TsGenerator : public BaseGenerator {
|
||||
auto &enum_def = **it;
|
||||
GenEnum(enum_def, &enumcode, imports, false);
|
||||
GenEnum(enum_def, &enumcode, imports, true);
|
||||
std::string type_name = GetTypeName(enum_def);
|
||||
TrackNsDef(enum_def, type_name);
|
||||
SaveType(enum_def, enumcode, imports, bare_imports);
|
||||
imports_all_.insert(imports.begin(), imports.end());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,70 +226,103 @@ class TsGenerator : public BaseGenerator {
|
||||
import_set bare_imports;
|
||||
import_set imports;
|
||||
AddImport(bare_imports, "* as flatbuffers", "flatbuffers");
|
||||
import_flatbuffers_lib_ = true;
|
||||
auto &struct_def = **it;
|
||||
std::string declcode;
|
||||
GenStruct(parser_, struct_def, &declcode, imports);
|
||||
std::string type_name = GetTypeName(struct_def);
|
||||
TrackNsDef(struct_def, type_name);
|
||||
SaveType(struct_def, declcode, imports, bare_imports);
|
||||
imports_all_.insert(imports.begin(), imports.end());
|
||||
}
|
||||
}
|
||||
|
||||
// Generate code for a single entry point module.
|
||||
void generateEntry() {
|
||||
std::string code =
|
||||
"// " + std::string(FlatBuffersGeneratedWarning()) + "\n\n";
|
||||
if (parser_.opts.ts_flat_file) {
|
||||
if (import_flatbuffers_lib_) {
|
||||
code += "import * as flatbuffers from 'flatbuffers';\n";
|
||||
code += "\n";
|
||||
}
|
||||
// Only include import statements when not generating all.
|
||||
if (!parser_.opts.generate_all) {
|
||||
for (const auto &it : flat_file_import_declarations_) {
|
||||
// Note that we do end up generating an import for ourselves, which
|
||||
// should generally be harmless.
|
||||
// TODO: Make it so we don't generate a self-import; this will also
|
||||
// require modifying AddImport to ensure that we don't use
|
||||
// namespace-prefixed names anywhere...
|
||||
std::string file = it.first;
|
||||
if (file.empty()) { continue; }
|
||||
std::string noext = flatbuffers::StripExtension(file);
|
||||
std::string basename = flatbuffers::StripPath(noext);
|
||||
std::string include_file = GeneratedFileName(
|
||||
parser_.opts.include_prefix,
|
||||
parser_.opts.keep_prefix ? noext : basename, parser_.opts);
|
||||
// TODO: what is the right behavior when different include flags are
|
||||
// specified here? Should we always be adding the "./" for a relative
|
||||
// path or turn it off if --include-prefix is specified, or something
|
||||
// else?
|
||||
std::string include_name =
|
||||
"./" + flatbuffers::StripExtension(include_file);
|
||||
code += "import {";
|
||||
for (const auto &pair : it.second) {
|
||||
code += namer_.EscapeKeyword(pair.first) + " as " +
|
||||
namer_.EscapeKeyword(pair.second) + ", ";
|
||||
}
|
||||
code.resize(code.size() - 2);
|
||||
code += "} from '" + include_name + ".js';\n";
|
||||
}
|
||||
code += "\n";
|
||||
std::string code;
|
||||
|
||||
// add root namespace def if not already existing from defs tracking
|
||||
std::string root;
|
||||
if (ns_defs_.count(root) == 0) {
|
||||
NsDefinition nsDef;
|
||||
nsDef.path = root;
|
||||
nsDef.symbolic_name = file_name_;
|
||||
nsDef.filepath = path_ + file_name_ + ".ts";
|
||||
nsDef.ns = new Namespace();
|
||||
ns_defs_[nsDef.path] = nsDef;
|
||||
}
|
||||
|
||||
for (const auto &it : ns_defs_) {
|
||||
code = "// " + std::string(FlatBuffersGeneratedWarning()) + "\n\n";
|
||||
|
||||
// export all definitions in ns entry point module
|
||||
int export_counter = 0;
|
||||
for (const auto &def : it.second.definitions) {
|
||||
std::vector<std::string> rel_components;
|
||||
// build path for root level vs child level
|
||||
if (it.second.ns->components.size() > 1)
|
||||
std::copy(it.second.ns->components.begin() + 1,
|
||||
it.second.ns->components.end(),
|
||||
std::back_inserter(rel_components));
|
||||
else
|
||||
std::copy(it.second.ns->components.begin(),
|
||||
it.second.ns->components.end(),
|
||||
std::back_inserter(rel_components));
|
||||
auto base_file_name =
|
||||
namer_.File(*(def.second), SkipFile::SuffixAndExtension);
|
||||
auto base_name =
|
||||
namer_.Directories(it.second.ns->components, SkipDir::OutputPath) +
|
||||
base_file_name;
|
||||
auto ts_file_path = base_name + ".ts";
|
||||
auto base_name_rel = std::string("./");
|
||||
base_name_rel +=
|
||||
namer_.Directories(rel_components, SkipDir::OutputPath);
|
||||
base_name_rel += base_file_name;
|
||||
auto ts_file_path_rel = base_name_rel + ".ts";
|
||||
auto type_name = def.first;
|
||||
code += "export { " + type_name + " } from '";
|
||||
std::string import_extension =
|
||||
parser_.opts.ts_no_import_ext ? "" : ".js";
|
||||
code += base_name_rel + import_extension + "';\n";
|
||||
export_counter++;
|
||||
}
|
||||
|
||||
code += flat_file_;
|
||||
const std::string filename =
|
||||
GeneratedFileName(path_, file_name_, parser_.opts);
|
||||
SaveFile(filename.c_str(), code, false);
|
||||
} else {
|
||||
for (auto it = imports_all_.begin(); it != imports_all_.end(); it++) {
|
||||
code += it->second.export_statement + "\n";
|
||||
// re-export child namespace(s) in parent
|
||||
const auto child_ns_level = it.second.ns->components.size() + 1;
|
||||
for (const auto &it2 : ns_defs_) {
|
||||
if (it2.second.ns->components.size() != child_ns_level) continue;
|
||||
auto ts_file_path = it2.second.path + ".ts";
|
||||
code += "export * as " + it2.second.symbolic_name + " from './";
|
||||
std::string rel_path = it2.second.path;
|
||||
code += rel_path + ".js';\n";
|
||||
export_counter++;
|
||||
}
|
||||
const std::string path =
|
||||
GeneratedFileName(path_, file_name_, parser_.opts);
|
||||
SaveFile(path.c_str(), code, false);
|
||||
|
||||
if (export_counter > 0) SaveFile(it.second.filepath.c_str(), code, false);
|
||||
}
|
||||
}
|
||||
|
||||
bool generateBundle() {
|
||||
if (parser_.opts.ts_flat_files) {
|
||||
std::string inputpath;
|
||||
std::string symbolic_name = file_name_;
|
||||
inputpath = path_ + file_name_ + ".ts";
|
||||
std::string bundlepath =
|
||||
GeneratedFileName(path_, file_name_, parser_.opts);
|
||||
bundlepath = bundlepath.substr(0, bundlepath.size() - 3) + ".js";
|
||||
std::string cmd = "esbuild";
|
||||
cmd += " ";
|
||||
cmd += inputpath;
|
||||
// cmd += " --minify";
|
||||
cmd += " --format=cjs --bundle --outfile=";
|
||||
cmd += bundlepath;
|
||||
cmd += " --external:flatbuffers";
|
||||
std::cout << "Entry point " << inputpath << " generated." << std::endl;
|
||||
std::cout << "A single file bundle can be created using fx. esbuild with:"
|
||||
<< std::endl;
|
||||
std::cout << "> " << cmd << std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Generate a documentation comment, if available.
|
||||
static void GenDocComment(const std::vector<std::string> &dc,
|
||||
std::string *code_ptr,
|
||||
@@ -831,28 +871,6 @@ class TsGenerator : public BaseGenerator {
|
||||
const std::string object_name =
|
||||
GetTypeName(dependency, /*object_api=*/true, has_name_clash);
|
||||
|
||||
if (parser_.opts.ts_flat_file) {
|
||||
// In flat-file generation, do not attempt to import things from ourselves
|
||||
// *and* do not wrap namespaces (note that this does override the logic
|
||||
// above, but since we force all non-self-imports to use namespace-based
|
||||
// names in flat file generation, it's fine).
|
||||
if (dependent.file == dependency.file) {
|
||||
name = import_name;
|
||||
} else {
|
||||
const std::string file =
|
||||
RelativeToRootPath(StripFileName(AbsolutePath(dependent.file)),
|
||||
dependency.file)
|
||||
// Strip the leading //
|
||||
.substr(2);
|
||||
flat_file_import_declarations_[file][import_name] = name;
|
||||
|
||||
if (parser_.opts.generate_object_based_api &&
|
||||
SupportsObjectAPI<DefinitionT>::value) {
|
||||
flat_file_import_declarations_[file][import_name + "T"] = object_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const std::string symbols_expression = GenSymbolExpression(
|
||||
dependency, has_name_clash, import_name, name, object_name);
|
||||
|
||||
@@ -876,10 +894,11 @@ class TsGenerator : public BaseGenerator {
|
||||
import.object_name = object_name;
|
||||
import.bare_file_path = bare_file_path;
|
||||
import.rel_file_path = rel_file_path;
|
||||
std::string import_extension = parser_.opts.ts_no_import_ext ? "" : ".js";
|
||||
import.import_statement = "import { " + symbols_expression + " } from '" +
|
||||
rel_file_path + ".js';";
|
||||
rel_file_path + import_extension + "';";
|
||||
import.export_statement = "export { " + symbols_expression + " } from '." +
|
||||
bare_file_path + ".js';";
|
||||
bare_file_path + import_extension + "';";
|
||||
import.dependency = &dependency;
|
||||
import.dependent = &dependent;
|
||||
|
||||
|
||||
@@ -970,6 +970,14 @@ CheckedError Parser::ParseField(StructDef &struct_def) {
|
||||
FieldDef *field;
|
||||
ECHECK(AddField(struct_def, name, type, &field));
|
||||
|
||||
if (typefield) {
|
||||
// We preserve the relation between the typefield
|
||||
// and field, so we can easily map it in the code
|
||||
// generators.
|
||||
typefield->sibling_union_field = field;
|
||||
field->sibling_union_field = typefield;
|
||||
}
|
||||
|
||||
if (token_ == '=') {
|
||||
NEXT();
|
||||
ECHECK(ParseSingleValue(&field->name, field->value, true));
|
||||
@@ -3895,7 +3903,7 @@ bool FieldDef::Deserialize(Parser &parser, const reflection::Field *field) {
|
||||
if (IsInteger(value.type.base_type)) {
|
||||
value.constant = NumToString(field->default_integer());
|
||||
} else if (IsFloat(value.type.base_type)) {
|
||||
value.constant = FloatToString(field->default_real(), 16);
|
||||
value.constant = FloatToString(field->default_real(), 17);
|
||||
}
|
||||
presence = FieldDef::MakeFieldPresence(field->optional(), field->required());
|
||||
padding = field->padding();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
--swiftversion 5.1
|
||||
--swiftversion 5.7
|
||||
|
||||
# format
|
||||
--indent 2
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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.
|
||||
@@ -429,13 +429,13 @@ public struct ByteBuffer {
|
||||
}
|
||||
|
||||
/// Returns the written bytes into the ``ByteBuffer``
|
||||
public var underlyingBytes: [UInt8] {
|
||||
let cp = capacity &- writerIndex
|
||||
let start = memory.advanced(by: writerIndex)
|
||||
.bindMemory(to: UInt8.self, capacity: cp)
|
||||
public var underlyingBytes: [UInt8] {
|
||||
let cp = capacity &- writerIndex
|
||||
let start = memory.advanced(by: writerIndex)
|
||||
.bindMemory(to: UInt8.self, capacity: cp)
|
||||
|
||||
let ptr = UnsafeBufferPointer<UInt8>(start: start, count: cp)
|
||||
return Array(ptr)
|
||||
let ptr = UnsafeBufferPointer<UInt8>(start: start, count: cp)
|
||||
return Array(ptr)
|
||||
}
|
||||
|
||||
/// SkipPrefix Skips the first 4 bytes in case one of the following
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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.
|
||||
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
|
||||
#if !os(WASI)
|
||||
#if os(Linux)
|
||||
import CoreFoundation
|
||||
#else
|
||||
import Foundation
|
||||
#endif
|
||||
#if os(Linux)
|
||||
import CoreFoundation
|
||||
#else
|
||||
import Foundation
|
||||
#endif
|
||||
#else
|
||||
import SwiftOverlayShims
|
||||
#endif
|
||||
@@ -119,4 +119,4 @@ extension UInt64: Scalar, Verifiable {
|
||||
public typealias NumericValue = UInt64
|
||||
}
|
||||
|
||||
public func FlatBuffersVersion_23_1_4() {}
|
||||
public func FlatBuffersVersion_23_1_21() {}
|
||||
|
||||
@@ -4,8 +4,8 @@ import Foundation
|
||||
func run() {
|
||||
// create a ByteBuffer(:) from an [UInt8] or Data()
|
||||
let buf = [] // Get your data
|
||||
|
||||
var byteBuffer = ByteBuffer(bytes: buf)
|
||||
// Get an accessor to the root object inside the buffer.
|
||||
let monster: Monster = try! getCheckedRoot(byteBuffer: ByteBuffer(bytes: buf))
|
||||
// let monster: Monster = getRoot(byteBuffer: ByteBuffer(bytes: buf))
|
||||
let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
|
||||
// let monster: Monster = getRoot(byteBuffer: &byteBuffer)
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ import Foundation
|
||||
func run() {
|
||||
// create a ByteBuffer(:) from an [UInt8] or Data()
|
||||
let buf = [] // Get your data
|
||||
|
||||
var byteBuffer = ByteBuffer(bytes: buf)
|
||||
// Get an accessor to the root object inside the buffer.
|
||||
let monster: Monster = try! getCheckedRoot(byteBuffer: ByteBuffer(bytes: buf))
|
||||
// let monster: Monster = getRoot(byteBuffer: ByteBuffer(bytes: buf))
|
||||
let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
|
||||
// let monster: Monster = getRoot(byteBuffer: &byteBuffer)
|
||||
|
||||
let hp = monster.hp
|
||||
let mana = monster.mana
|
||||
|
||||
@@ -4,10 +4,10 @@ import Foundation
|
||||
func run() {
|
||||
// create a ByteBuffer(:) from an [UInt8] or Data()
|
||||
let buf = [] // Get your data
|
||||
|
||||
var byteBuffer = ByteBuffer(bytes: buf)
|
||||
// Get an accessor to the root object inside the buffer.
|
||||
let monster: Monster = try! getCheckedRoot(byteBuffer: ByteBuffer(bytes: buf))
|
||||
// let monster: Monster = getRoot(byteBuffer: ByteBuffer(bytes: buf))
|
||||
let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
|
||||
// let monster: Monster = getRoot(byteBuffer: &byteBuffer)
|
||||
|
||||
let hp = monster.hp
|
||||
let mana = monster.mana
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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.
|
||||
@@ -66,12 +66,12 @@ public enum FlatbuffersErrors: Error, Equatable {
|
||||
#if !os(WASI)
|
||||
|
||||
extension FlatbuffersErrors {
|
||||
public static func == (
|
||||
lhs: FlatbuffersErrors,
|
||||
rhs: FlatbuffersErrors) -> Bool
|
||||
{
|
||||
lhs.localizedDescription == rhs.localizedDescription
|
||||
}
|
||||
public static func == (
|
||||
lhs: FlatbuffersErrors,
|
||||
rhs: FlatbuffersErrors) -> Bool
|
||||
{
|
||||
lhs.localizedDescription == rhs.localizedDescription
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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 2021 Google Inc. All rights reserved.
|
||||
* Copyright 2023 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.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||
Or modify. I'm a message, not a cop.
|
||||
|
||||
flatc version: 23.1.4
|
||||
flatc version: 23.1.21
|
||||
|
||||
Declared by :
|
||||
]#
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class LongFloatEntry extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_1_4(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_1_21(); }
|
||||
public static LongFloatEntry getRootAsLongFloatEntry(ByteBuffer _bb) { return getRootAsLongFloatEntry(_bb, new LongFloatEntry()); }
|
||||
public static LongFloatEntry getRootAsLongFloatEntry(ByteBuffer _bb, LongFloatEntry obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
|
||||
@@ -2,11 +2,24 @@
|
||||
|
||||
package DictionaryLookup
|
||||
|
||||
import java.nio.*
|
||||
import com.google.flatbuffers.BaseVector
|
||||
import com.google.flatbuffers.BooleanVector
|
||||
import com.google.flatbuffers.ByteVector
|
||||
import com.google.flatbuffers.Constants
|
||||
import com.google.flatbuffers.DoubleVector
|
||||
import com.google.flatbuffers.FlatBufferBuilder
|
||||
import com.google.flatbuffers.FloatVector
|
||||
import com.google.flatbuffers.LongVector
|
||||
import com.google.flatbuffers.StringVector
|
||||
import com.google.flatbuffers.Struct
|
||||
import com.google.flatbuffers.Table
|
||||
import com.google.flatbuffers.UnionVector
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import kotlin.math.sign
|
||||
import com.google.flatbuffers.*
|
||||
|
||||
@Suppress("unused")
|
||||
@kotlin.ExperimentalUnsignedTypes
|
||||
class LongFloatEntry : Table() {
|
||||
|
||||
fun __init(_i: Int, _bb: ByteBuffer) {
|
||||
@@ -32,7 +45,7 @@ class LongFloatEntry : Table() {
|
||||
return (val_1 - val_2).sign
|
||||
}
|
||||
companion object {
|
||||
fun validateVersion() = Constants.FLATBUFFERS_23_1_4()
|
||||
fun validateVersion() = Constants.FLATBUFFERS_23_1_21()
|
||||
fun getRootAsLongFloatEntry(_bb: ByteBuffer): LongFloatEntry = getRootAsLongFloatEntry(_bb, LongFloatEntry())
|
||||
fun getRootAsLongFloatEntry(_bb: ByteBuffer, obj: LongFloatEntry): LongFloatEntry {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class LongFloatMap extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_1_4(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_1_21(); }
|
||||
public static LongFloatMap getRootAsLongFloatMap(ByteBuffer _bb) { return getRootAsLongFloatMap(_bb, new LongFloatMap()); }
|
||||
public static LongFloatMap getRootAsLongFloatMap(ByteBuffer _bb, LongFloatMap obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
|
||||
@@ -2,11 +2,24 @@
|
||||
|
||||
package DictionaryLookup
|
||||
|
||||
import java.nio.*
|
||||
import com.google.flatbuffers.BaseVector
|
||||
import com.google.flatbuffers.BooleanVector
|
||||
import com.google.flatbuffers.ByteVector
|
||||
import com.google.flatbuffers.Constants
|
||||
import com.google.flatbuffers.DoubleVector
|
||||
import com.google.flatbuffers.FlatBufferBuilder
|
||||
import com.google.flatbuffers.FloatVector
|
||||
import com.google.flatbuffers.LongVector
|
||||
import com.google.flatbuffers.StringVector
|
||||
import com.google.flatbuffers.Struct
|
||||
import com.google.flatbuffers.Table
|
||||
import com.google.flatbuffers.UnionVector
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import kotlin.math.sign
|
||||
import com.google.flatbuffers.*
|
||||
|
||||
@Suppress("unused")
|
||||
@kotlin.ExperimentalUnsignedTypes
|
||||
class LongFloatMap : Table() {
|
||||
|
||||
fun __init(_i: Int, _bb: ByteBuffer) {
|
||||
@@ -46,7 +59,7 @@ class LongFloatMap : Table() {
|
||||
}
|
||||
}
|
||||
companion object {
|
||||
fun validateVersion() = Constants.FLATBUFFERS_23_1_4()
|
||||
fun validateVersion() = Constants.FLATBUFFERS_23_1_21()
|
||||
fun getRootAsLongFloatMap(_bb: ByteBuffer): LongFloatMap = getRootAsLongFloatMap(_bb, LongFloatMap())
|
||||
fun getRootAsLongFloatMap(_bb: ByteBuffer, obj: LongFloatMap): LongFloatMap {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
|
||||
@@ -169,6 +169,9 @@
|
||||
<Compile Include="..\nested_namespace_test\nested_namespace_test3_generated.cs">
|
||||
<Link>nested_namespace_test\nested_namespace_test3_generated.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\union_value_collsion\union_value_collision_generated.cs">
|
||||
<Link>union_value_collsion\union_value_collision_generated.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -13,7 +13,7 @@ public struct KeywordsInTable : IFlatbufferObject
|
||||
{
|
||||
private Table __p;
|
||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_23_1_4(); }
|
||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_23_1_21(); }
|
||||
public static KeywordsInTable GetRootAsKeywordsInTable(ByteBuffer _bb) { return GetRootAsKeywordsInTable(_bb, new KeywordsInTable()); }
|
||||
public static KeywordsInTable GetRootAsKeywordsInTable(ByteBuffer _bb, KeywordsInTable obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); }
|
||||
|
||||
@@ -13,7 +13,7 @@ public struct Table2 : IFlatbufferObject
|
||||
{
|
||||
private Table __p;
|
||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_23_1_4(); }
|
||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_23_1_21(); }
|
||||
public static Table2 GetRootAsTable2(ByteBuffer _bb) { return GetRootAsTable2(_bb, new Table2()); }
|
||||
public static Table2 GetRootAsTable2(ByteBuffer _bb, Table2 obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||
Or modify. I'm a message, not a cop.
|
||||
|
||||
flatc version: 23.1.4
|
||||
flatc version: 23.1.21
|
||||
|
||||
Declared by :
|
||||
]#
|
||||
|
||||
@@ -2,11 +2,24 @@
|
||||
|
||||
package MyGame.Example
|
||||
|
||||
import java.nio.*
|
||||
import com.google.flatbuffers.BaseVector
|
||||
import com.google.flatbuffers.BooleanVector
|
||||
import com.google.flatbuffers.ByteVector
|
||||
import com.google.flatbuffers.Constants
|
||||
import com.google.flatbuffers.DoubleVector
|
||||
import com.google.flatbuffers.FlatBufferBuilder
|
||||
import com.google.flatbuffers.FloatVector
|
||||
import com.google.flatbuffers.LongVector
|
||||
import com.google.flatbuffers.StringVector
|
||||
import com.google.flatbuffers.Struct
|
||||
import com.google.flatbuffers.Table
|
||||
import com.google.flatbuffers.UnionVector
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import kotlin.math.sign
|
||||
import com.google.flatbuffers.*
|
||||
|
||||
@Suppress("unused")
|
||||
@kotlin.ExperimentalUnsignedTypes
|
||||
class Ability : Struct() {
|
||||
|
||||
fun __init(_i: Int, _bb: ByteBuffer) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user