mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-16 17:22:21 +00:00
Compare commits
114 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
af9ceabeef | ||
|
|
3b2eb77595 | ||
|
|
6420fa5c88 | ||
|
|
01589630ba | ||
|
|
e0d68bdda2 | ||
|
|
e43a80c322 | ||
|
|
449d5649d6 | ||
|
|
96d438df47 | ||
|
|
4e396d47bc | ||
|
|
b47ba1d5ff | ||
|
|
a078130c87 | ||
|
|
9ed76559df | ||
|
|
9927747d4e | ||
|
|
52d1b77941 | ||
|
|
40aa964057 | ||
|
|
e1a2f688e0 | ||
|
|
c0797b22ae | ||
|
|
97ee210826 | ||
|
|
3be296ec8a | ||
|
|
acf39ff056 | ||
|
|
0e79e56427 | ||
|
|
aadc4cb8be | ||
|
|
b5ebd3fd78 | ||
|
|
11394575bc | ||
|
|
5b7b36e8be | ||
|
|
c0230d839b | ||
|
|
a8d49f2972 | ||
|
|
416c6020eb | ||
|
|
6d95867a8f | ||
|
|
2eaf790638 | ||
|
|
3b2ced0131 | ||
|
|
00af4e23b3 | ||
|
|
7e00b754f0 | ||
|
|
cf89d1e756 | ||
|
|
ad6054c600 | ||
|
|
c3a01c7228 | ||
|
|
533f75d91b | ||
|
|
fcab80f1bb | ||
|
|
5d2d0b92b1 | ||
|
|
ae6662374d | ||
|
|
7b6c9f4a3c | ||
|
|
5a42b2c76c | ||
|
|
8f625561d0 | ||
|
|
9d2c04d629 | ||
|
|
e000458bb1 | ||
|
|
60975d6f7e | ||
|
|
1cba8b2b49 | ||
|
|
eead6c6219 | ||
|
|
bb9b9dad5f | ||
|
|
ade9e19be0 | ||
|
|
eb1abb51ea | ||
|
|
1fa6091000 | ||
|
|
634c2ee7e3 | ||
|
|
6f895f54c2 | ||
|
|
41d6903294 | ||
|
|
7b038e3277 | ||
|
|
74756e5d1b | ||
|
|
879622fc57 | ||
|
|
83e7a98f69 | ||
|
|
f20b0a45b3 | ||
|
|
207708efef | ||
|
|
225578a8b3 | ||
|
|
459e8acc37 | ||
|
|
8aa8b9139e | ||
|
|
001adf782d | ||
|
|
dbc58ab77c | ||
|
|
2facfeec7e | ||
|
|
4de2814c7b | ||
|
|
37b1acdaff | ||
|
|
a22434e2a1 | ||
|
|
214cc94681 | ||
|
|
a4ff275d9b | ||
|
|
15f32c6907 | ||
|
|
051afd8825 | ||
|
|
728c033ad6 | ||
|
|
4c514483d8 | ||
|
|
c2d9c20803 | ||
|
|
e34ae4c6b6 | ||
|
|
e54536127c | ||
|
|
49d9f941c0 | ||
|
|
cefc21c1f9 | ||
|
|
3e64fa7246 | ||
|
|
b15f3c57ea | ||
|
|
ff802c6802 | ||
|
|
b401957d5f | ||
|
|
8c8151f8f9 | ||
|
|
ebb7c203d3 |
347
.clang-tidy
Normal file
347
.clang-tidy
Normal file
@@ -0,0 +1,347 @@
|
|||||||
|
---
|
||||||
|
FormatStyle: "file"
|
||||||
|
WarningsAsErrors: "*"
|
||||||
|
HeaderFilterRegex: ".*"
|
||||||
|
Checks: "google-build-explicit-make-pair,
|
||||||
|
google-build-namespaces,
|
||||||
|
google-build-using-namespace,
|
||||||
|
google-default-arguments,
|
||||||
|
google-explicit-constructor,
|
||||||
|
google-global-names-in-headers,
|
||||||
|
google-objc-avoid-nsobject-new,
|
||||||
|
google-objc-avoid-throwing-exception,
|
||||||
|
google-objc-function-naming,
|
||||||
|
google-objc-global-variable-declaration,
|
||||||
|
google-readability-avoid-underscore-in-googletest-name,
|
||||||
|
google-readability-braces-around-statements,
|
||||||
|
google-readability-casting,
|
||||||
|
google-readability-function-size,
|
||||||
|
google-readability-namespace-comments,
|
||||||
|
google-runtime-int,
|
||||||
|
google-runtime-operator,
|
||||||
|
google-upgrade-googletest-case,
|
||||||
|
clang-analyzer-apiModeling.StdCLibraryFunctions,
|
||||||
|
clang-analyzer-apiModeling.TrustNonnull,
|
||||||
|
clang-analyzer-apiModeling.google.GTest,
|
||||||
|
clang-analyzer-apiModeling.llvm.CastValue,
|
||||||
|
clang-analyzer-apiModeling.llvm.ReturnValue,
|
||||||
|
clang-analyzer-core.CallAndMessage,
|
||||||
|
clang-analyzer-core.CallAndMessageModeling,
|
||||||
|
clang-analyzer-core.DivideZero,
|
||||||
|
clang-analyzer-core.DynamicTypePropagation,
|
||||||
|
clang-analyzer-core.NonNullParamChecker,
|
||||||
|
clang-analyzer-core.NonnilStringConstants,
|
||||||
|
clang-analyzer-core.NullDereference,
|
||||||
|
clang-analyzer-core.StackAddrEscapeBase,
|
||||||
|
clang-analyzer-core.StackAddressEscape,
|
||||||
|
clang-analyzer-core.UndefinedBinaryOperatorResult,
|
||||||
|
clang-analyzer-core.VLASize,
|
||||||
|
clang-analyzer-core.builtin.BuiltinFunctions,
|
||||||
|
clang-analyzer-core.builtin.NoReturnFunctions,
|
||||||
|
clang-analyzer-core.uninitialized.ArraySubscript,
|
||||||
|
clang-analyzer-core.uninitialized.Assign,
|
||||||
|
clang-analyzer-core.uninitialized.Branch,
|
||||||
|
clang-analyzer-core.uninitialized.CapturedBlockVariable,
|
||||||
|
clang-analyzer-core.uninitialized.UndefReturn,
|
||||||
|
clang-analyzer-cplusplus.InnerPointer,
|
||||||
|
clang-analyzer-cplusplus.Move,
|
||||||
|
clang-analyzer-cplusplus.NewDelete,
|
||||||
|
clang-analyzer-cplusplus.NewDeleteLeaks,
|
||||||
|
clang-analyzer-cplusplus.PlacementNew,
|
||||||
|
clang-analyzer-cplusplus.PureVirtualCall,
|
||||||
|
clang-analyzer-cplusplus.SelfAssignment,
|
||||||
|
clang-analyzer-cplusplus.SmartPtrModeling,
|
||||||
|
clang-analyzer-cplusplus.StringChecker,
|
||||||
|
clang-analyzer-cplusplus.VirtualCallModeling,
|
||||||
|
clang-analyzer-deadcode.DeadStores,
|
||||||
|
clang-analyzer-fuchsia.HandleChecker,
|
||||||
|
clang-analyzer-nullability.NullPassedToNonnull,
|
||||||
|
clang-analyzer-nullability.NullReturnedFromNonnull,
|
||||||
|
clang-analyzer-nullability.NullabilityBase,
|
||||||
|
clang-analyzer-nullability.NullableDereferenced,
|
||||||
|
clang-analyzer-nullability.NullablePassedToNonnull,
|
||||||
|
clang-analyzer-nullability.NullableReturnedFromNonnull,
|
||||||
|
clang-analyzer-optin.cplusplus.UninitializedObject,
|
||||||
|
clang-analyzer-optin.cplusplus.VirtualCall,
|
||||||
|
clang-analyzer-optin.mpi.MPI-Checker,
|
||||||
|
clang-analyzer-optin.osx.OSObjectCStyleCast,
|
||||||
|
clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker,
|
||||||
|
clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker,
|
||||||
|
clang-analyzer-optin.performance.GCDAntipattern,
|
||||||
|
clang-analyzer-optin.performance.Padding,
|
||||||
|
clang-analyzer-optin.portability.UnixAPI,
|
||||||
|
clang-analyzer-osx.API,
|
||||||
|
clang-analyzer-osx.MIG,
|
||||||
|
clang-analyzer-osx.NSOrCFErrorDerefChecker,
|
||||||
|
clang-analyzer-osx.NumberObjectConversion,
|
||||||
|
clang-analyzer-osx.OSObjectRetainCount,
|
||||||
|
clang-analyzer-osx.ObjCProperty,
|
||||||
|
clang-analyzer-osx.SecKeychainAPI,
|
||||||
|
clang-analyzer-osx.cocoa.AtSync,
|
||||||
|
clang-analyzer-osx.cocoa.AutoreleaseWrite,
|
||||||
|
clang-analyzer-osx.cocoa.ClassRelease,
|
||||||
|
clang-analyzer-osx.cocoa.Dealloc,
|
||||||
|
clang-analyzer-osx.cocoa.IncompatibleMethodTypes,
|
||||||
|
clang-analyzer-osx.cocoa.Loops,
|
||||||
|
clang-analyzer-osx.cocoa.MissingSuperCall,
|
||||||
|
clang-analyzer-osx.cocoa.NSAutoreleasePool,
|
||||||
|
clang-analyzer-osx.cocoa.NSError,
|
||||||
|
clang-analyzer-osx.cocoa.NilArg,
|
||||||
|
clang-analyzer-osx.cocoa.NonNilReturnValue,
|
||||||
|
clang-analyzer-osx.cocoa.ObjCGenerics,
|
||||||
|
clang-analyzer-osx.cocoa.RetainCount,
|
||||||
|
clang-analyzer-osx.cocoa.RetainCountBase,
|
||||||
|
clang-analyzer-osx.cocoa.RunLoopAutoreleaseLeak,
|
||||||
|
clang-analyzer-osx.cocoa.SelfInit,
|
||||||
|
clang-analyzer-osx.cocoa.SuperDealloc,
|
||||||
|
clang-analyzer-osx.cocoa.UnusedIvars,
|
||||||
|
clang-analyzer-osx.cocoa.VariadicMethodTypes,
|
||||||
|
clang-analyzer-osx.coreFoundation.CFError,
|
||||||
|
clang-analyzer-osx.coreFoundation.CFNumber,
|
||||||
|
clang-analyzer-osx.coreFoundation.CFRetainRelease,
|
||||||
|
clang-analyzer-osx.coreFoundation.containers.OutOfBounds,
|
||||||
|
clang-analyzer-osx.coreFoundation.containers.PointerSizedValues,
|
||||||
|
clang-analyzer-security.FloatLoopCounter,
|
||||||
|
clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
|
||||||
|
clang-analyzer-security.insecureAPI.SecuritySyntaxChecker,
|
||||||
|
clang-analyzer-security.insecureAPI.UncheckedReturn,
|
||||||
|
clang-analyzer-security.insecureAPI.bcmp,
|
||||||
|
clang-analyzer-security.insecureAPI.bcopy,
|
||||||
|
clang-analyzer-security.insecureAPI.bzero,
|
||||||
|
clang-analyzer-security.insecureAPI.decodeValueOfObjCType,
|
||||||
|
clang-analyzer-security.insecureAPI.getpw,
|
||||||
|
clang-analyzer-security.insecureAPI.gets,
|
||||||
|
clang-analyzer-security.insecureAPI.mkstemp,
|
||||||
|
clang-analyzer-security.insecureAPI.mktemp,
|
||||||
|
clang-analyzer-security.insecureAPI.rand,
|
||||||
|
clang-analyzer-security.insecureAPI.strcpy,
|
||||||
|
clang-analyzer-security.insecureAPI.vfork,
|
||||||
|
clang-analyzer-unix.API,
|
||||||
|
clang-analyzer-unix.DynamicMemoryModeling,
|
||||||
|
clang-analyzer-unix.Malloc,
|
||||||
|
clang-analyzer-unix.MallocSizeof,
|
||||||
|
clang-analyzer-unix.MismatchedDeallocator,
|
||||||
|
clang-analyzer-unix.Vfork,
|
||||||
|
clang-analyzer-unix.cstring.BadSizeArg,
|
||||||
|
clang-analyzer-unix.cstring.CStringModeling,
|
||||||
|
clang-analyzer-unix.cstring.NullArg,
|
||||||
|
clang-analyzer-valist.CopyToSelf,
|
||||||
|
clang-analyzer-valist.Uninitialized,
|
||||||
|
clang-analyzer-valist.Unterminated,
|
||||||
|
clang-analyzer-valist.ValistBase,
|
||||||
|
clang-analyzer-webkit.NoUncountedMemberChecker,
|
||||||
|
clang-analyzer-webkit.RefCntblBaseVirtualDtor,
|
||||||
|
clang-analyzer-webkit.UncountedLambdaCapturesChecker,
|
||||||
|
|
||||||
|
################################################ Optional checks ################################################
|
||||||
|
|
||||||
|
#google-readability-todo,
|
||||||
|
#bugprone-argument-comment,
|
||||||
|
#bugprone-assert-side-effect,
|
||||||
|
#bugprone-bad-signal-to-kill-thread,
|
||||||
|
#bugprone-bool-pointer-implicit-conversion,
|
||||||
|
#bugprone-branch-clone,
|
||||||
|
#bugprone-copy-constructor-init,
|
||||||
|
#bugprone-dangling-handle,
|
||||||
|
#bugprone-dynamic-static-initializers,
|
||||||
|
#bugprone-easily-swappable-parameters,
|
||||||
|
#bugprone-exception-escape,
|
||||||
|
#bugprone-fold-init-type,
|
||||||
|
#bugprone-forward-declaration-namespace,
|
||||||
|
#bugprone-forwarding-reference-overload,
|
||||||
|
#bugprone-implicit-widening-of-multiplication-result,
|
||||||
|
#bugprone-inaccurate-erase,
|
||||||
|
#bugprone-incorrect-roundings,
|
||||||
|
#bugprone-infinite-loop,
|
||||||
|
#bugprone-integer-division,
|
||||||
|
#bugprone-lambda-function-name,
|
||||||
|
#bugprone-macro-parentheses,
|
||||||
|
#bugprone-macro-repeated-side-effects,
|
||||||
|
#bugprone-misplaced-operator-in-strlen-in-alloc,
|
||||||
|
#bugprone-misplaced-pointer-arithmetic-in-alloc,
|
||||||
|
#bugprone-misplaced-widening-cast,
|
||||||
|
#bugprone-move-forwarding-reference,
|
||||||
|
#bugprone-multiple-statement-macro,
|
||||||
|
#bugprone-narrowing-conversions,
|
||||||
|
#bugprone-no-escape,
|
||||||
|
#bugprone-not-null-terminated-result,
|
||||||
|
#bugprone-parent-virtual-call,
|
||||||
|
#bugprone-posix-return,
|
||||||
|
#bugprone-redundant-branch-condition,
|
||||||
|
#bugprone-reserved-identifier,
|
||||||
|
#bugprone-signal-handler,
|
||||||
|
#bugprone-signed-char-misuse,
|
||||||
|
#bugprone-sizeof-container,
|
||||||
|
#bugprone-sizeof-expression,
|
||||||
|
#bugprone-spuriously-wake-up-functions,
|
||||||
|
#bugprone-string-constructor,
|
||||||
|
#bugprone-string-integer-assignment,
|
||||||
|
#bugprone-string-literal-with-embedded-nul,
|
||||||
|
#bugprone-stringview-nullptr,
|
||||||
|
#bugprone-suspicious-enum-usage,
|
||||||
|
#bugprone-suspicious-include,
|
||||||
|
#bugprone-suspicious-memory-comparison,
|
||||||
|
#bugprone-suspicious-memset-usage,
|
||||||
|
#bugprone-suspicious-missing-comma,
|
||||||
|
#bugprone-suspicious-semicolon,
|
||||||
|
#bugprone-suspicious-string-compare,
|
||||||
|
#bugprone-swapped-arguments,
|
||||||
|
#bugprone-terminating-continue,
|
||||||
|
#bugprone-throw-keyword-missing,
|
||||||
|
#bugprone-too-small-loop-variable,
|
||||||
|
#bugprone-undefined-memory-manipulation,
|
||||||
|
#bugprone-undelegated-constructor,
|
||||||
|
#bugprone-unhandled-exception-at-new,
|
||||||
|
#bugprone-unhandled-self-assignment,
|
||||||
|
#bugprone-unused-raii,
|
||||||
|
#bugprone-unused-return-value,
|
||||||
|
#bugprone-use-after-move,
|
||||||
|
#bugprone-virtual-near-miss,
|
||||||
|
#cppcoreguidelines-avoid-c-arrays,
|
||||||
|
#cppcoreguidelines-avoid-goto,
|
||||||
|
#cppcoreguidelines-avoid-magic-numbers,
|
||||||
|
#cppcoreguidelines-avoid-non-const-global-variables,
|
||||||
|
#cppcoreguidelines-c-copy-assignment-signature,
|
||||||
|
#cppcoreguidelines-explicit-virtual-functions,
|
||||||
|
#cppcoreguidelines-init-variables,
|
||||||
|
#cppcoreguidelines-interfaces-global-init,
|
||||||
|
#cppcoreguidelines-macro-usage,
|
||||||
|
#cppcoreguidelines-narrowing-conversions,
|
||||||
|
#cppcoreguidelines-no-malloc,
|
||||||
|
#cppcoreguidelines-non-private-member-variables-in-classes,
|
||||||
|
#cppcoreguidelines-owning-memory,
|
||||||
|
#cppcoreguidelines-prefer-member-initializer,
|
||||||
|
#cppcoreguidelines-pro-bounds-array-to-pointer-decay,
|
||||||
|
#cppcoreguidelines-pro-bounds-constant-array-index,
|
||||||
|
#cppcoreguidelines-pro-bounds-pointer-arithmetic,
|
||||||
|
#cppcoreguidelines-pro-type-const-cast,
|
||||||
|
#cppcoreguidelines-pro-type-cstyle-cast,
|
||||||
|
#cppcoreguidelines-pro-type-member-init,
|
||||||
|
#cppcoreguidelines-pro-type-reinterpret-cast,
|
||||||
|
#cppcoreguidelines-pro-type-static-cast-downcast,
|
||||||
|
#cppcoreguidelines-pro-type-union-access,
|
||||||
|
#cppcoreguidelines-pro-type-vararg,
|
||||||
|
#cppcoreguidelines-slicing,
|
||||||
|
#cppcoreguidelines-special-member-functions,
|
||||||
|
#cppcoreguidelines-virtual-class-destructor,
|
||||||
|
#hicpp-avoid-c-arrays,
|
||||||
|
#hicpp-avoid-goto,
|
||||||
|
#hicpp-braces-around-statements,
|
||||||
|
#hicpp-deprecated-headers,
|
||||||
|
#hicpp-exception-baseclass,
|
||||||
|
#hicpp-explicit-conversions,
|
||||||
|
#hicpp-function-size,
|
||||||
|
#hicpp-invalid-access-moved,
|
||||||
|
#hicpp-member-init,
|
||||||
|
#hicpp-move-const-arg,
|
||||||
|
#hicpp-multiway-paths-covered,
|
||||||
|
#hicpp-named-parameter,
|
||||||
|
#hicpp-new-delete-operators,
|
||||||
|
#hicpp-no-array-decay,
|
||||||
|
#hicpp-no-assembler,
|
||||||
|
#hicpp-no-malloc,
|
||||||
|
#hicpp-noexcept-move,
|
||||||
|
#hicpp-signed-bitwise,
|
||||||
|
#hicpp-special-member-functions,
|
||||||
|
#hicpp-static-assert,
|
||||||
|
#hicpp-undelegated-constructor,
|
||||||
|
#hicpp-uppercase-literal-suffix,
|
||||||
|
#hicpp-use-auto,
|
||||||
|
#hicpp-use-emplace,
|
||||||
|
#hicpp-use-equals-default,
|
||||||
|
#hicpp-use-equals-delete,
|
||||||
|
#hicpp-use-noexcept,
|
||||||
|
#hicpp-use-nullptr,
|
||||||
|
#hicpp-use-override,
|
||||||
|
#hicpp-vararg,
|
||||||
|
#modernize-avoid-bind,
|
||||||
|
#modernize-avoid-c-arrays,
|
||||||
|
#modernize-concat-nested-namespaces,
|
||||||
|
#modernize-deprecated-headers,
|
||||||
|
#modernize-deprecated-ios-base-aliases,
|
||||||
|
#modernize-loop-convert,
|
||||||
|
#modernize-make-shared,
|
||||||
|
#modernize-make-unique,
|
||||||
|
#modernize-pass-by-value,
|
||||||
|
#modernize-raw-string-literal,
|
||||||
|
#modernize-redundant-void-arg,
|
||||||
|
#modernize-replace-auto-ptr,
|
||||||
|
#modernize-replace-disallow-copy-and-assign-macro,
|
||||||
|
#modernize-replace-random-shuffle,
|
||||||
|
#modernize-return-braced-init-list,
|
||||||
|
#modernize-shrink-to-fit,
|
||||||
|
#modernize-unary-static-assert,
|
||||||
|
#modernize-use-auto,
|
||||||
|
#modernize-use-bool-literals,
|
||||||
|
#modernize-use-default-member-init,
|
||||||
|
#modernize-use-emplace,
|
||||||
|
#modernize-use-equals-default,
|
||||||
|
#modernize-use-equals-delete,
|
||||||
|
#modernize-use-nodiscard,
|
||||||
|
#modernize-use-noexcept,
|
||||||
|
#modernize-use-nullptr,
|
||||||
|
#modernize-use-override,
|
||||||
|
#modernize-use-trailing-return-type,
|
||||||
|
#modernize-use-transparent-functors,
|
||||||
|
#modernize-use-uncaught-exceptions,
|
||||||
|
#modernize-use-using,
|
||||||
|
#performance-faster-string-find,
|
||||||
|
#performance-for-range-copy,
|
||||||
|
#performance-implicit-conversion-in-loop,
|
||||||
|
#performance-inefficient-algorithm,
|
||||||
|
#performance-inefficient-string-concatenation,
|
||||||
|
#performance-inefficient-vector-operation,
|
||||||
|
#performance-move-const-arg,
|
||||||
|
#performance-move-constructor-init,
|
||||||
|
#performance-no-automatic-move,
|
||||||
|
#performance-no-int-to-ptr,
|
||||||
|
#performance-noexcept-move-constructor,
|
||||||
|
#performance-trivially-destructible,
|
||||||
|
#performance-type-promotion-in-math-fn,
|
||||||
|
#performance-unnecessary-copy-initialization,
|
||||||
|
#performance-unnecessary-value-param,
|
||||||
|
#portability-restrict-system-includes,
|
||||||
|
#portability-simd-intrinsics,
|
||||||
|
#readability-avoid-const-params-in-decls,
|
||||||
|
#readability-braces-around-statements,
|
||||||
|
#readability-const-return-type,
|
||||||
|
#readability-container-contains,
|
||||||
|
#readability-container-data-pointer,
|
||||||
|
#readability-container-size-empty,
|
||||||
|
#readability-convert-member-functions-to-static,
|
||||||
|
#readability-delete-null-pointer,
|
||||||
|
#readability-duplicate-include,
|
||||||
|
#readability-else-after-return,
|
||||||
|
#readability-function-cognitive-complexity,
|
||||||
|
#readability-function-size,
|
||||||
|
#readability-identifier-length,
|
||||||
|
#readability-identifier-naming,
|
||||||
|
#readability-implicit-bool-conversion,
|
||||||
|
#readability-inconsistent-declaration-parameter-name,
|
||||||
|
#readability-isolate-declaration,
|
||||||
|
#readability-magic-numbers,
|
||||||
|
#readability-make-member-function-const,
|
||||||
|
#readability-misleading-indentation,
|
||||||
|
#readability-misplaced-array-index,
|
||||||
|
#readability-named-parameter,
|
||||||
|
#readability-non-const-parameter,
|
||||||
|
#readability-qualified-auto,
|
||||||
|
#readability-redundant-access-specifiers,
|
||||||
|
#readability-redundant-control-flow,
|
||||||
|
#readability-redundant-declaration,
|
||||||
|
#readability-redundant-function-ptr-dereference,
|
||||||
|
#readability-redundant-member-init,
|
||||||
|
#readability-redundant-preprocessor,
|
||||||
|
#readability-redundant-smartptr-get,
|
||||||
|
#readability-redundant-string-cstr,
|
||||||
|
#readability-redundant-string-init,
|
||||||
|
#readability-simplify-boolean-expr,
|
||||||
|
#readability-simplify-subscript-expr,
|
||||||
|
#readability-static-accessed-through-instance,
|
||||||
|
#readability-static-definition-in-anonymous-namespace,
|
||||||
|
#readability-string-compare,
|
||||||
|
#readability-suspicious-call-argument,
|
||||||
|
#readability-uniqueptr-delete-release,
|
||||||
|
#readability-uppercase-literal-suffix,
|
||||||
|
#readability-use-anyofallof
|
||||||
|
"
|
||||||
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -3,7 +3,7 @@ Thank you for submitting a PR!
|
|||||||
Please delete this standard text once you've created your own description.
|
Please delete this standard text once you've created your own description.
|
||||||
|
|
||||||
If you make changes to any of the code generators (`src/idl_gen*`) be sure to
|
If you make changes to any of the code generators (`src/idl_gen*`) be sure to
|
||||||
build your project, as it will generate code based on the changes. If necessary
|
[build](https://google.github.io/flatbuffers/flatbuffers_guide_building.html) your project, as it will generate code based on the changes. If necessary
|
||||||
the code generation script can be directly run (`scripts/generate_code.py`),
|
the code generation script can be directly run (`scripts/generate_code.py`),
|
||||||
requires Python3. This allows us to better see the effect of the PR.
|
requires Python3. This allows us to better see the effect of the PR.
|
||||||
|
|
||||||
|
|||||||
154
.github/workflows/build.yml
vendored
154
.github/workflows/build.yml
vendored
@@ -27,7 +27,7 @@ jobs:
|
|||||||
cxx: [g++-10, clang++-12]
|
cxx: [g++-10, clang++-12]
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
- name: build
|
- name: build
|
||||||
@@ -63,6 +63,16 @@ jobs:
|
|||||||
id: hash-gcc
|
id: hash-gcc
|
||||||
run: echo "::set-output name=hashes::$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)"
|
run: echo "::set-output name=hashes::$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)"
|
||||||
|
|
||||||
|
build-linux-no-file-tests:
|
||||||
|
name: Build Linux with -DFLATBUFFERS_NO_FILE_TESTS
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: cmake
|
||||||
|
run: CXX=clang++-12 cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_CXX_FLAGS="-DFLATBUFFERS_NO_FILE_TESTS" .
|
||||||
|
- name: build
|
||||||
|
run: make -j
|
||||||
|
|
||||||
build-linux-cpp-std:
|
build-linux-cpp-std:
|
||||||
name: Build Linux C++
|
name: Build Linux C++
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -76,7 +86,7 @@ jobs:
|
|||||||
- cxx: g++-10
|
- cxx: g++-10
|
||||||
std: 23
|
std: 23
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: >
|
run: >
|
||||||
CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles"
|
CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles"
|
||||||
@@ -99,7 +109,7 @@ jobs:
|
|||||||
std: [11, 14, 17, 20, 23]
|
std: [11, 14, 17, 20, 23]
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Add msbuild to PATH
|
- name: Add msbuild to PATH
|
||||||
uses: microsoft/setup-msbuild@v1.1
|
uses: microsoft/setup-msbuild@v1.1
|
||||||
- name: cmake
|
- name: cmake
|
||||||
@@ -124,7 +134,7 @@ jobs:
|
|||||||
name: Build Windows 2019
|
name: Build Windows 2019
|
||||||
runs-on: windows-2019
|
runs-on: windows-2019
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Add msbuild to PATH
|
- name: Add msbuild to PATH
|
||||||
uses: microsoft/setup-msbuild@v1.1
|
uses: microsoft/setup-msbuild@v1.1
|
||||||
- name: cmake
|
- name: cmake
|
||||||
@@ -159,7 +169,7 @@ jobs:
|
|||||||
name: Build Windows 2017
|
name: Build Windows 2017
|
||||||
runs-on: windows-2019
|
runs-on: windows-2019
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Add msbuild to PATH
|
- name: Add msbuild to PATH
|
||||||
uses: microsoft/setup-msbuild@v1.1
|
uses: microsoft/setup-msbuild@v1.1
|
||||||
- name: cmake
|
- name: cmake
|
||||||
@@ -173,7 +183,7 @@ jobs:
|
|||||||
name: Build Windows 2015
|
name: Build Windows 2015
|
||||||
runs-on: windows-2019
|
runs-on: windows-2019
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Add msbuild to PATH
|
- name: Add msbuild to PATH
|
||||||
uses: microsoft/setup-msbuild@v1.1
|
uses: microsoft/setup-msbuild@v1.1
|
||||||
- name: cmake
|
- name: cmake
|
||||||
@@ -195,9 +205,9 @@ jobs:
|
|||||||
#'-p:EnableSpanT=true,UnsafeByteBuffer=true'
|
#'-p:EnableSpanT=true,UnsafeByteBuffer=true'
|
||||||
]
|
]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Setup .NET Core SDK
|
- name: Setup .NET Core SDK
|
||||||
uses: actions/setup-dotnet@v1.9.0
|
uses: actions/setup-dotnet@v3
|
||||||
with:
|
with:
|
||||||
dotnet-version: '3.1.x'
|
dotnet-version: '3.1.x'
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -219,34 +229,33 @@ jobs:
|
|||||||
name: Build Mac (for Intel)
|
name: Build Mac (for Intel)
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_FLATC_EXECUTABLE=_build/Release/flatc -DFLATBUFFERS_STRICT_MODE=ON .
|
run: cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
- name: build
|
- name: build
|
||||||
# NOTE: we need this _build dir to not have xcodebuild's default ./build dir clash with the BUILD file.
|
run: xcodebuild -toolchain clang -configuration Release -target flattests
|
||||||
run: xcodebuild -toolchain clang -configuration Release -target flattests SYMROOT=$(PWD)/_build
|
|
||||||
- name: check that the binary is x86_64
|
- name: check that the binary is x86_64
|
||||||
run: |
|
run: |
|
||||||
info=$(file _build/Release/flatc)
|
info=$(file Release/flatc)
|
||||||
echo $info
|
echo $info
|
||||||
echo $info | grep "Mach-O 64-bit executable x86_64"
|
echo $info | grep "Mach-O 64-bit executable x86_64"
|
||||||
- name: test
|
- name: test
|
||||||
run: _build/Release/flattests
|
run: Release/flattests
|
||||||
- name: make flatc executable
|
- name: make flatc executable
|
||||||
run: |
|
run: |
|
||||||
chmod +x _build/Release/flatc
|
chmod +x Release/flatc
|
||||||
./_build/Release/flatc --version
|
Release/flatc --version
|
||||||
- name: flatc tests
|
- name: flatc tests
|
||||||
run: python3 tests/flatc/main.py --flatc ./_build/Release/flatc
|
run: python3 tests/flatc/main.py --flatc Release/flatc
|
||||||
- name: upload build artifacts
|
- name: upload build artifacts
|
||||||
uses: actions/upload-artifact@v1
|
uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
name: Mac flatc binary
|
name: Mac flatc binary
|
||||||
path: _build/Release/flatc
|
path: Release/flatc
|
||||||
# Below if only for release.
|
# Below if only for release.
|
||||||
- name: Zip file
|
- name: Zip file
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
run: mv _build/Release/flatc . && zip MacIntel.flatc.binary.zip flatc
|
run: mv Release/flatc . && zip MacIntel.flatc.binary.zip flatc
|
||||||
- name: Release binary
|
- name: Release binary
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
@@ -265,32 +274,31 @@ jobs:
|
|||||||
name: Build Mac (universal build)
|
name: Build Mac (universal build)
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: cmake -G "Xcode" -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_FLATC_EXECUTABLE=_build/Release/flatc -DFLATBUFFERS_STRICT_MODE=ON .
|
run: cmake -G "Xcode" -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
- name: build
|
- name: build
|
||||||
# NOTE: we need this _build dir to not have xcodebuild's default ./build dir clash with the BUILD file.
|
run: xcodebuild -toolchain clang -configuration Release -target flattests
|
||||||
run: xcodebuild -toolchain clang -configuration Release -target flattests SYMROOT=$(PWD)/_build
|
|
||||||
- name: check that the binary is "universal"
|
- name: check that the binary is "universal"
|
||||||
run: |
|
run: |
|
||||||
info=$(file _build/Release/flatc)
|
info=$(file Release/flatc)
|
||||||
echo $info
|
echo $info
|
||||||
echo $info | grep "Mach-O universal binary with 2 architectures"
|
echo $info | grep "Mach-O universal binary with 2 architectures"
|
||||||
- name: test
|
- name: test
|
||||||
run: _build/Release/flattests
|
run: Release/flattests
|
||||||
- name: make flatc executable
|
- name: make flatc executable
|
||||||
run: |
|
run: |
|
||||||
chmod +x _build/Release/flatc
|
chmod +x Release/flatc
|
||||||
./_build/Release/flatc --version
|
Release/flatc --version
|
||||||
- name: upload build artifacts
|
- name: upload build artifacts
|
||||||
uses: actions/upload-artifact@v1
|
uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
name: Mac flatc binary
|
name: Mac flatc binary
|
||||||
path: _build/Release/flatc
|
path: Release/flatc
|
||||||
# Below if only for release.
|
# Below if only for release.
|
||||||
- name: Zip file
|
- name: Zip file
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
run: mv _build/Release/flatc . && zip Mac.flatc.binary.zip flatc
|
run: mv Release/flatc . && zip Mac.flatc.binary.zip flatc
|
||||||
- name: Release binary
|
- name: Release binary
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
@@ -305,11 +313,12 @@ jobs:
|
|||||||
name: Build Android (on Linux)
|
name: Build Android (on Linux)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: set up JDK 1.8
|
- name: set up Java
|
||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
java-version: 1.8
|
distribution: 'temurin'
|
||||||
|
java-version: '11'
|
||||||
- name: set up flatc
|
- name: set up flatc
|
||||||
run: |
|
run: |
|
||||||
cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON .
|
cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
@@ -326,7 +335,7 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
cxx: [g++-10, clang++-12]
|
cxx: [g++-10, clang++-12]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DFLATBUFFERS_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DFLATBUFFERS_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
||||||
- name: Generate
|
- name: Generate
|
||||||
@@ -334,6 +343,22 @@ jobs:
|
|||||||
- name: Generate gRPC
|
- name: Generate gRPC
|
||||||
run: scripts/check-grpc-generated-code.py
|
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:
|
build-benchmarks:
|
||||||
name: Build Benchmarks (on Linux)
|
name: Build Benchmarks (on Linux)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -341,7 +366,7 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
cxx: [g++-10]
|
cxx: [g++-10]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DFLATBUFFERS_CXX_FLAGS="-Wno-unused-parameter -fno-aligned-new" -DFLATBUFFERS_BUILD_BENCHMARKS=ON -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DFLATBUFFERS_CXX_FLAGS="-Wno-unused-parameter -fno-aligned-new" -DFLATBUFFERS_BUILD_BENCHMARKS=ON -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
||||||
- name: Run benchmarks
|
- name: Run benchmarks
|
||||||
@@ -356,7 +381,7 @@ jobs:
|
|||||||
name: Build Java
|
name: Build Java
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: java
|
working-directory: java
|
||||||
run: mvn test
|
run: mvn test
|
||||||
@@ -366,11 +391,11 @@ jobs:
|
|||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- uses: gradle/wrapper-validation-action@v1
|
- uses: gradle/wrapper-validation-action@v1.0.5
|
||||||
- uses: actions/setup-java@v2
|
- uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
distribution: 'adopt-hotspot'
|
distribution: 'temurin'
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
- name: Build
|
- name: Build
|
||||||
working-directory: kotlin
|
working-directory: kotlin
|
||||||
@@ -381,16 +406,16 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- uses: actions/setup-java@v2
|
- uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
distribution: 'adopt-hotspot'
|
distribution: 'temurin'
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
- uses: gradle/wrapper-validation-action@v1
|
- uses: gradle/wrapper-validation-action@v1.0.5
|
||||||
- name: Build
|
- name: Build
|
||||||
working-directory: kotlin
|
working-directory: kotlin
|
||||||
# we are using docker's version of gradle
|
# we are using docker's version of gradle
|
||||||
# so no need for wrapper validadation or user
|
# so no need for wrapper validation or user
|
||||||
# gradlew
|
# gradlew
|
||||||
run: gradle jvmMainClasses jvmTest jsTest jsBrowserTest
|
run: gradle jvmMainClasses jvmTest jsTest jsBrowserTest
|
||||||
|
|
||||||
@@ -398,7 +423,7 @@ jobs:
|
|||||||
name: Build Rust
|
name: Build Rust
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: tests
|
working-directory: tests
|
||||||
run: bash RustTest.sh
|
run: bash RustTest.sh
|
||||||
@@ -407,7 +432,7 @@ jobs:
|
|||||||
name: Build Python
|
name: Build Python
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: tests
|
working-directory: tests
|
||||||
run: bash PythonTest.sh
|
run: bash PythonTest.sh
|
||||||
@@ -416,7 +441,7 @@ jobs:
|
|||||||
name: Build Go
|
name: Build Go
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: flatc
|
- name: flatc
|
||||||
# FIXME: make test script not rely on flatc
|
# FIXME: make test script not rely on flatc
|
||||||
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
||||||
@@ -424,14 +449,30 @@ jobs:
|
|||||||
working-directory: tests
|
working-directory: tests
|
||||||
run: bash GoTest.sh
|
run: bash GoTest.sh
|
||||||
|
|
||||||
|
build-php:
|
||||||
|
name: Build PHP
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: flatc
|
||||||
|
# FIXME: make test script not rely on flatc
|
||||||
|
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
||||||
|
- name: test
|
||||||
|
working-directory: tests
|
||||||
|
run: |
|
||||||
|
php phpTest.php
|
||||||
|
sh phpUnionVectorTest.sh
|
||||||
|
|
||||||
build-swift:
|
build-swift:
|
||||||
name: Build Swift
|
name: Build Swift
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: tests/swift/tests
|
working-directory: tests/swift/tests
|
||||||
run: sh SwiftTest.sh
|
run: |
|
||||||
|
swift build --build-tests
|
||||||
|
swift test
|
||||||
|
|
||||||
build-swift-wasm:
|
build-swift-wasm:
|
||||||
name: Build Swift Wasm
|
name: Build Swift Wasm
|
||||||
@@ -439,9 +480,9 @@ jobs:
|
|||||||
container:
|
container:
|
||||||
image: ghcr.io/swiftwasm/carton:0.15.3
|
image: ghcr.io/swiftwasm/carton:0.15.3
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Setup Wasmer
|
- name: Setup Wasmer
|
||||||
uses: wasmerio/setup-wasmer@v1
|
uses: wasmerio/setup-wasmer@v2
|
||||||
- name: Test
|
- name: Test
|
||||||
working-directory: tests/swift/Wasm.tests
|
working-directory: tests/swift/Wasm.tests
|
||||||
run: carton test
|
run: carton test
|
||||||
@@ -450,7 +491,7 @@ jobs:
|
|||||||
name: Build TS
|
name: Build TS
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: flatc
|
- name: flatc
|
||||||
# FIXME: make test script not rely on flatc
|
# FIXME: make test script not rely on flatc
|
||||||
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j
|
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j
|
||||||
@@ -466,7 +507,7 @@ jobs:
|
|||||||
name: Build Dart
|
name: Build Dart
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: dart-lang/setup-dart@v1
|
- uses: dart-lang/setup-dart@v1
|
||||||
with:
|
with:
|
||||||
sdk: stable
|
sdk: stable
|
||||||
@@ -481,7 +522,7 @@ jobs:
|
|||||||
name: Build Nim
|
name: Build Nim
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: flatc
|
- name: flatc
|
||||||
# FIXME: make test script not rely on flatc
|
# FIXME: make test script not rely on flatc
|
||||||
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j
|
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j
|
||||||
@@ -524,7 +565,8 @@ jobs:
|
|||||||
actions: read # To read the workflow path.
|
actions: read # To read the workflow path.
|
||||||
id-token: write # To sign the provenance.
|
id-token: write # To sign the provenance.
|
||||||
contents: write # To add assets to a release.
|
contents: write # To add assets to a release.
|
||||||
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.2.0
|
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.2.1
|
||||||
with:
|
with:
|
||||||
base64-subjects: "${{ needs.release-digests.outputs.digests }}"
|
base64-subjects: "${{ needs.release-digests.outputs.digests }}"
|
||||||
upload-assets: true # Optional: Upload to a new release
|
upload-assets: true # Optional: Upload to a new release
|
||||||
|
compile-generator: true # Workaround for https://github.com/slsa-framework/slsa-github-generator/issues/1163
|
||||||
|
|||||||
35
.github/workflows/extrabuild.yml
vendored
Normal file
35
.github/workflows/extrabuild.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
name: Build and unit tests that are more time consuming
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
|
on:
|
||||||
|
# For manual tests.
|
||||||
|
workflow_dispatch:
|
||||||
|
pull_request:
|
||||||
|
types:
|
||||||
|
- closed
|
||||||
|
schedule:
|
||||||
|
- cron: "30 20 * * *"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-linux-s390x:
|
||||||
|
name: Build Linux on s390x arch and run unit tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: uraimo/run-on-arch-action@v2
|
||||||
|
name: Run commands
|
||||||
|
id: runcmd
|
||||||
|
with:
|
||||||
|
arch: s390x
|
||||||
|
distro: ubuntu_latest
|
||||||
|
install: |
|
||||||
|
apt-get update -q -y
|
||||||
|
apt-get -y install cmake
|
||||||
|
apt-get -y install make
|
||||||
|
apt-get -y install g++
|
||||||
|
run: |
|
||||||
|
lscpu | grep Endian
|
||||||
|
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
|
||||||
|
make -j
|
||||||
|
./flattests
|
||||||
|
|
||||||
52
.github/workflows/release.yml
vendored
52
.github/workflows/release.yml
vendored
@@ -17,6 +17,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: '16.x'
|
node-version: '16.x'
|
||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: 'https://registry.npmjs.org'
|
||||||
|
|
||||||
- run: npm publish
|
- run: npm publish
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
@@ -49,6 +50,57 @@ jobs:
|
|||||||
TWINE_USERNAME: __token__
|
TWINE_USERNAME: __token__
|
||||||
TWINE_PASSWORD: ${{ secrets.TWINE_TOKEN }}
|
TWINE_PASSWORD: ${{ secrets.TWINE_TOKEN }}
|
||||||
|
|
||||||
|
publish-nuget:
|
||||||
|
name: Publish NuGet
|
||||||
|
runs-on: windows-latest
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: ./net/flatbuffers
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-dotnet@v3
|
||||||
|
with:
|
||||||
|
dotnet-version: '6.0.x'
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
dotnet build Google.FlatBuffers.csproj -c Release
|
||||||
|
|
||||||
|
- name: Pack
|
||||||
|
run: |
|
||||||
|
dotnet pack Google.FlatBuffers.csproj -c Release
|
||||||
|
|
||||||
|
- name: Upload to NuGet
|
||||||
|
run: |
|
||||||
|
dotnet nuget push .\bin\Release\Google.FlatBuffers.*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
|
||||||
|
|
||||||
|
publish-maven:
|
||||||
|
name: Publish Maven
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: ./java
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Maven Central Repository
|
||||||
|
uses: actions/setup-java@v3
|
||||||
|
with:
|
||||||
|
java-version: '11'
|
||||||
|
distribution: 'adopt'
|
||||||
|
cache: 'maven'
|
||||||
|
server-id: ossrh
|
||||||
|
server-username: OSSRH_USERNAME
|
||||||
|
server-password: OSSRH_PASSWORD
|
||||||
|
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
|
||||||
|
gpg-passphrase: MAVEN_GPG_PASSPHRASE # this needs to be an env var
|
||||||
|
|
||||||
|
- name: Publish Maven
|
||||||
|
run: mvn --batch-mode clean deploy
|
||||||
|
env:
|
||||||
|
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
|
||||||
|
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
|
||||||
|
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -149,4 +149,5 @@ flatbuffers.pc
|
|||||||
**/html/**
|
**/html/**
|
||||||
**/latex/**
|
**/latex/**
|
||||||
# https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_BASE_DIR
|
# https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_BASE_DIR
|
||||||
|
cmake-build-debug/
|
||||||
_deps/
|
_deps/
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ filegroup(
|
|||||||
"include/flatbuffers/bfbs_generator.h",
|
"include/flatbuffers/bfbs_generator.h",
|
||||||
"include/flatbuffers/buffer.h",
|
"include/flatbuffers/buffer.h",
|
||||||
"include/flatbuffers/buffer_ref.h",
|
"include/flatbuffers/buffer_ref.h",
|
||||||
|
"include/flatbuffers/code_generator.h",
|
||||||
"include/flatbuffers/code_generators.h",
|
"include/flatbuffers/code_generators.h",
|
||||||
"include/flatbuffers/default_allocator.h",
|
"include/flatbuffers/default_allocator.h",
|
||||||
"include/flatbuffers/detached_buffer.h",
|
"include/flatbuffers/detached_buffer.h",
|
||||||
|
|||||||
32
CHANGELOG.md
32
CHANGELOG.md
@@ -4,15 +4,41 @@ All major or breaking changes will be documented in this file, as well as any
|
|||||||
new features that should be highlighted. Minor fixes or improvements are not
|
new features that should be highlighted. Minor fixes or improvements are not
|
||||||
necessarily listed.
|
necessarily listed.
|
||||||
|
|
||||||
## 22.10.25 (Oct 25 2002)
|
## [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](https://github.com/google/flatbuffers/issues/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
|
||||||
|
[versioning scheme](https://github.com/google/flatbuffers/wiki/Versioning) of
|
||||||
|
using a date to signify releases. This results in the first release of the new
|
||||||
|
year to bump the tradition major version field.
|
||||||
|
|
||||||
|
* Go minimum version is now 1.19 (#7720) with the addition of Go modules.
|
||||||
|
|
||||||
|
* Added CI support for Big Endian regression testing (#7707).
|
||||||
|
|
||||||
|
* Fixed `getFullyQualifiedName` in typescript to return name delimited by '.'
|
||||||
|
instead of '_' (#7730).
|
||||||
|
|
||||||
|
* Fixed the versioning scheme to not include leading zeros which are not
|
||||||
|
consistently handled by every package manager. Only the last release
|
||||||
|
(12.12.06) should have suffered from this.
|
||||||
|
|
||||||
|
## [22.12.06 (Dec 06 2022)](https://github.com/google/flatbuffers/releases/tag/v22.12.06)
|
||||||
|
|
||||||
|
* Bug fixing release, no major changes.
|
||||||
|
|
||||||
|
## [22.10.25 (Oct 25 2022)](https://github.com/google/flatbuffers/releases/tag/v22.10.25)
|
||||||
|
|
||||||
* Added Nim language support with generator and runtime libraries (#7534).
|
* Added Nim language support with generator and runtime libraries (#7534).
|
||||||
|
|
||||||
## 22.9.29 (Sept 29 2022)
|
## [22.9.29 (Sept 29 2022)](https://github.com/google/flatbuffers/releases/tag/v22.9.29)
|
||||||
|
|
||||||
* Rust soundness fixes to avoid the crate from bing labelled unsafe (#7518).
|
* Rust soundness fixes to avoid the crate from bing labelled unsafe (#7518).
|
||||||
|
|
||||||
## 22.9.24 (Sept 24 2022)
|
## [22.9.24 (Sept 24 2022)](https://github.com/google/flatbuffers/releases/tag/v22.9.24)
|
||||||
|
|
||||||
* 20 Major releases in a row? Nope, we switched to a new
|
* 20 Major releases in a row? Nope, we switched to a new
|
||||||
[versioning scheme](https://github.com/google/flatbuffers/wiki/Versioning)
|
[versioning scheme](https://github.com/google/flatbuffers/wiki/Versioning)
|
||||||
|
|||||||
@@ -438,14 +438,12 @@ endif()
|
|||||||
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||||
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
||||||
|
|
||||||
# Shared object version: "major.minor.micro"
|
# FlatBuffers use calendar-based versioning and do not provide any ABI
|
||||||
# - micro updated every release when there is no API/ABI changes
|
# stability guarantees. Therefore, always use the full version as SOVERSION
|
||||||
# - minor updated when there are additions in API/ABI
|
# in order to avoid breaking reverse dependencies on upgrades.
|
||||||
# - major (ABI number) updated when there are changes in ABI (or removals)
|
set(FlatBuffers_Library_SONAME_FULL "${PROJECT_VERSION}")
|
||||||
set(FlatBuffers_Library_SONAME_MAJOR ${VERSION_MAJOR})
|
|
||||||
set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
|
||||||
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
|
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
|
||||||
SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}"
|
SOVERSION "${FlatBuffers_Library_SONAME_FULL}"
|
||||||
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
||||||
if(FLATBUFFERS_ENABLE_PCH)
|
if(FLATBUFFERS_ENABLE_PCH)
|
||||||
add_pch_to_target(flatbuffers_shared include/flatbuffers/pch/pch.h)
|
add_pch_to_target(flatbuffers_shared include/flatbuffers/pch/pch.h)
|
||||||
|
|||||||
@@ -1,37 +1,39 @@
|
|||||||
set(VERSION_MAJOR 22)
|
set(VERSION_MAJOR 23)
|
||||||
set(VERSION_MINOR 10)
|
set(VERSION_MINOR 1)
|
||||||
set(VERSION_PATCH 26)
|
set(VERSION_PATCH 20)
|
||||||
set(VERSION_COMMIT 0)
|
set(VERSION_COMMIT 0)
|
||||||
|
|
||||||
find_program(GIT git)
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||||
if(GIT AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
find_program(GIT git)
|
||||||
execute_process(
|
if(GIT)
|
||||||
|
execute_process(
|
||||||
COMMAND ${GIT} describe --tags
|
COMMAND ${GIT} describe --tags
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
OUTPUT_VARIABLE GIT_DESCRIBE_DIRTY
|
OUTPUT_VARIABLE GIT_DESCRIBE_DIRTY
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
RESULT_VARIABLE GIT_DESCRIBE_RESULT
|
RESULT_VARIABLE GIT_DESCRIBE_RESULT
|
||||||
)
|
)
|
||||||
|
|
||||||
if(GIT_DESCRIBE_RESULT EQUAL 0)
|
if(GIT_DESCRIBE_RESULT EQUAL 0)
|
||||||
# Test if the most recent Git tag matches the pattern "v<major>.<minor>.<patch>*"
|
# Test if the most recent Git tag matches the pattern "v<major>.<minor>.<patch>*"
|
||||||
if(GIT_DESCRIBE_DIRTY MATCHES "^v[0-9]+\\.[0-9]+\\.[0-9]+.*")
|
if(GIT_DESCRIBE_DIRTY MATCHES "^v[0-9]+\\.[0-9]+\\.[0-9]+.*")
|
||||||
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_DESCRIBE_DIRTY}")
|
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_DESCRIBE_DIRTY}")
|
||||||
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${GIT_DESCRIBE_DIRTY}")
|
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${GIT_DESCRIBE_DIRTY}")
|
||||||
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_DESCRIBE_DIRTY}")
|
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_DESCRIBE_DIRTY}")
|
||||||
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" VERSION_COMMIT "${GIT_DESCRIBE_DIRTY}")
|
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" VERSION_COMMIT "${GIT_DESCRIBE_DIRTY}")
|
||||||
# If the tag points to the commit, then only the tag is shown in "git describe"
|
# If the tag points to the commit, then only the tag is shown in "git describe"
|
||||||
if(VERSION_COMMIT STREQUAL GIT_DESCRIBE_DIRTY)
|
if(VERSION_COMMIT STREQUAL GIT_DESCRIBE_DIRTY)
|
||||||
set(VERSION_COMMIT 0)
|
set(VERSION_COMMIT 0)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(WARNING "\"${GIT_DESCRIBE_DIRTY}\" does not match pattern v<major>.<minor>.<patch>-<commit>")
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
message(WARNING "\"${GIT_DESCRIBE_DIRTY}\" does not match pattern v<major>.<minor>.<patch>-<commit>")
|
message(WARNING "git describe failed with exit code: ${GIT_DESCRIBE_RESULT}")
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
message(WARNING "git describe failed with exit code: ${GIT_DESCRIBE_RESULT}")
|
message(WARNING "git is not found")
|
||||||
endif()
|
endif()
|
||||||
else()
|
|
||||||
message(WARNING "git is not found")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
message(STATUS "Proceeding with version: ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_COMMIT}")
|
message(STATUS "Proceeding with version: ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_COMMIT}")
|
||||||
|
|||||||
@@ -125,6 +125,13 @@ if(NOT DEFINED FLATBUFFERS_LOCALE_INDEPENDENT)
|
|||||||
endif()
|
endif()
|
||||||
add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>)
|
add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>)
|
||||||
|
|
||||||
|
if(NOT WIN32)
|
||||||
|
check_symbol_exists(realpath "stdlib.h" HAVE_REALPATH)
|
||||||
|
if(NOT HAVE_REALPATH)
|
||||||
|
add_definitions(-DFLATBUFFERS_NO_ABSOLUTE_PATH_RESOLUTION)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
set(FlatBuffers_Library_SRCS
|
set(FlatBuffers_Library_SRCS
|
||||||
include/flatbuffers/allocator.h
|
include/flatbuffers/allocator.h
|
||||||
include/flatbuffers/array.h
|
include/flatbuffers/array.h
|
||||||
@@ -134,6 +141,7 @@ set(FlatBuffers_Library_SRCS
|
|||||||
include/flatbuffers/buffer_ref.h
|
include/flatbuffers/buffer_ref.h
|
||||||
include/flatbuffers/default_allocator.h
|
include/flatbuffers/default_allocator.h
|
||||||
include/flatbuffers/detached_buffer.h
|
include/flatbuffers/detached_buffer.h
|
||||||
|
include/flatbuffers/code_generator.h
|
||||||
include/flatbuffers/flatbuffer_builder.h
|
include/flatbuffers/flatbuffer_builder.h
|
||||||
include/flatbuffers/flatbuffers.h
|
include/flatbuffers/flatbuffers.h
|
||||||
include/flatbuffers/flexbuffers.h
|
include/flatbuffers/flexbuffers.h
|
||||||
@@ -219,6 +227,7 @@ set(FlatBuffers_Tests_SRCS
|
|||||||
tests/flexbuffers_test.cpp
|
tests/flexbuffers_test.cpp
|
||||||
tests/fuzz_test.cpp
|
tests/fuzz_test.cpp
|
||||||
tests/json_test.cpp
|
tests/json_test.cpp
|
||||||
|
tests/key_field_test.cpp
|
||||||
tests/monster_test.cpp
|
tests/monster_test.cpp
|
||||||
tests/optional_scalars_test.cpp
|
tests/optional_scalars_test.cpp
|
||||||
tests/parser_test.cpp
|
tests/parser_test.cpp
|
||||||
@@ -257,6 +266,8 @@ set(FlatBuffers_Tests_SRCS
|
|||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/native_inline_table_test_generated.h
|
${CMAKE_CURRENT_BINARY_DIR}/tests/native_inline_table_test_generated.h
|
||||||
# file generate by running compiler on tests/alignment_test.fbs
|
# file generate by running compiler on tests/alignment_test.fbs
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/alignment_test_generated.h
|
${CMAKE_CURRENT_BINARY_DIR}/tests/alignment_test_generated.h
|
||||||
|
# file generate by running compiler on tests/key_field/key_field_sample.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/key_field/key_field_sample_generated.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(FlatBuffers_Tests_CPP17_SRCS
|
set(FlatBuffers_Tests_CPP17_SRCS
|
||||||
@@ -416,6 +427,7 @@ else()
|
|||||||
|
|
||||||
# This isn't working for some reason: $<$<CXX_COMPILER_ID:CLANG>:
|
# This isn't working for some reason: $<$<CXX_COMPILER_ID:CLANG>:
|
||||||
$<$<BOOL:${IS_CLANG}>:
|
$<$<BOOL:${IS_CLANG}>:
|
||||||
|
-Wnewline-eof
|
||||||
-Wno-unknown-warning-option
|
-Wno-unknown-warning-option
|
||||||
-Wmissing-declarations
|
-Wmissing-declarations
|
||||||
-Wzero-as-null-pointer-constant
|
-Wzero-as-null-pointer-constant
|
||||||
@@ -513,14 +525,12 @@ endif()
|
|||||||
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||||
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
||||||
target_link_libraries(flatbuffers_shared PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
target_link_libraries(flatbuffers_shared PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
# Shared object version: "major.minor.micro"
|
# FlatBuffers use calendar-based versioning and do not provide any ABI
|
||||||
# - micro updated every release when there is no API/ABI changes
|
# stability guarantees. Therefore, always use the full version as SOVERSION
|
||||||
# - minor updated when there are additions in API/ABI
|
# in order to avoid breaking reverse dependencies on upgrades.
|
||||||
# - major (ABI number) updated when there are changes in ABI (or removals)
|
set(FlatBuffers_Library_SONAME_FULL "${PROJECT_VERSION}")
|
||||||
set(FlatBuffers_Library_SONAME_MAJOR ${VERSION_MAJOR})
|
|
||||||
set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
|
||||||
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
|
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
|
||||||
SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}"
|
SOVERSION "${FlatBuffers_Library_SONAME_FULL}"
|
||||||
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
||||||
if(FLATBUFFERS_ENABLE_PCH)
|
if(FLATBUFFERS_ENABLE_PCH)
|
||||||
add_pch_to_target(flatbuffers_shared include/flatbuffers/pch/pch.h)
|
add_pch_to_target(flatbuffers_shared include/flatbuffers/pch/pch.h)
|
||||||
@@ -578,7 +588,7 @@ function(compile_flatbuffers_schema_to_binary SRC_FBS)
|
|||||||
OUTPUT ${GEN_BINARY_SCHEMA}
|
OUTPUT ${GEN_BINARY_SCHEMA}
|
||||||
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||||
-b --schema --bfbs-comments --bfbs-builtins
|
-b --schema --bfbs-comments --bfbs-builtins
|
||||||
--bfbs-filenames ${SRC_FBS_DIR}
|
--bfbs-filenames "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS_DIR}"
|
||||||
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
||||||
-o "${SRC_FBS_DIR}"
|
-o "${SRC_FBS_DIR}"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||||
@@ -622,7 +632,7 @@ if(FLATBUFFERS_BUILD_TESTS)
|
|||||||
compile_flatbuffers_schema_to_binary(tests/monster_test.fbs)
|
compile_flatbuffers_schema_to_binary(tests/monster_test.fbs)
|
||||||
compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test1.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test1.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
||||||
compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test2.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test2.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
||||||
compile_flatbuffers_schema_to_cpp_opt(tests/union_vector/union_vector.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
compile_flatbuffers_schema_to_cpp_opt(tests/union_vector/union_vector.fbs "--no-includes;--gen-compare;")
|
||||||
compile_flatbuffers_schema_to_cpp(tests/optional_scalars.fbs)
|
compile_flatbuffers_schema_to_cpp(tests/optional_scalars.fbs)
|
||||||
compile_flatbuffers_schema_to_cpp_opt(tests/native_type_test.fbs "")
|
compile_flatbuffers_schema_to_cpp_opt(tests/native_type_test.fbs "")
|
||||||
compile_flatbuffers_schema_to_cpp_opt(tests/arrays_test.fbs "--scoped-enums;--gen-compare")
|
compile_flatbuffers_schema_to_cpp_opt(tests/arrays_test.fbs "--scoped-enums;--gen-compare")
|
||||||
@@ -630,6 +640,7 @@ if(FLATBUFFERS_BUILD_TESTS)
|
|||||||
compile_flatbuffers_schema_to_embedded_binary(tests/monster_test.fbs "--no-includes;--gen-compare")
|
compile_flatbuffers_schema_to_embedded_binary(tests/monster_test.fbs "--no-includes;--gen-compare")
|
||||||
compile_flatbuffers_schema_to_cpp(tests/native_inline_table_test.fbs "--gen-compare")
|
compile_flatbuffers_schema_to_cpp(tests/native_inline_table_test.fbs "--gen-compare")
|
||||||
compile_flatbuffers_schema_to_cpp(tests/alignment_test.fbs "--gen-compare")
|
compile_flatbuffers_schema_to_cpp(tests/alignment_test.fbs "--gen-compare")
|
||||||
|
compile_flatbuffers_schema_to_cpp(tests/key_field/key_field_sample.fbs)
|
||||||
if(NOT (MSVC AND (MSVC_VERSION LESS 1900)))
|
if(NOT (MSVC AND (MSVC_VERSION LESS 1900)))
|
||||||
compile_flatbuffers_schema_to_cpp(tests/monster_extra.fbs) # Test floating-point NAN/INF.
|
compile_flatbuffers_schema_to_cpp(tests/monster_extra.fbs) # Test floating-point NAN/INF.
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = 'FlatBuffers'
|
s.name = 'FlatBuffers'
|
||||||
s.version = '22.10.26'
|
s.version = '23.1.20'
|
||||||
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
||||||
|
|
||||||
s.description = "FlatBuffers is a cross platform serialization library architected for
|
s.description = "FlatBuffers is a cross platform serialization library architected for
|
||||||
|
|||||||
@@ -32,6 +32,6 @@ let package = Package(
|
|||||||
.target(
|
.target(
|
||||||
name: "FlatBuffers",
|
name: "FlatBuffers",
|
||||||
dependencies: [],
|
dependencies: [],
|
||||||
path: "swift/Sources")
|
path: "swift/Sources"),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ swift_rules_extra_dependencies()
|
|||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
name = "io_bazel_rules_go",
|
name = "io_bazel_rules_go",
|
||||||
sha256 = "16e9fca53ed6bd4ff4ad76facc9b7b651a89db1689a2877d6fd7b82aa824e366",
|
sha256 = "ae013bf35bd23234d1dea46b079f1e05ba74ac0321423830119d3e787ec73483",
|
||||||
urls = [
|
urls = [
|
||||||
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip",
|
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.36.0/rules_go-v0.36.0.zip",
|
||||||
"https://github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip",
|
"https://github.com/bazelbuild/rules_go/releases/download/v0.36.0/rules_go-v0.36.0.zip",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.example.FlatBufferTest">
|
package="com.example.FlatBufferTest">
|
||||||
|
|
||||||
|
<uses-sdk android:minSdkVersion="14"/>
|
||||||
<uses-feature android:glEsVersion="0x00020000"></uses-feature>
|
<uses-feature android:glEsVersion="0x00020000"></uses-feature>
|
||||||
|
|
||||||
<!-- This .apk has no Java code itself, so set hasCode to false. -->
|
<!-- This .apk has no Java code itself, so set hasCode to false. -->
|
||||||
|
|||||||
@@ -2,9 +2,21 @@
|
|||||||
|
|
||||||
package com.fbs.app
|
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 kotlin.math.sign
|
||||||
import com.google.flatbuffers.*
|
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
class Animal : Table() {
|
class Animal : Table() {
|
||||||
@@ -36,7 +48,7 @@ class Animal : Table() {
|
|||||||
return if(o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
|
return if(o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
|
||||||
}
|
}
|
||||||
companion object {
|
companion object {
|
||||||
fun validateVersion() = Constants.FLATBUFFERS_22_10_26()
|
fun validateVersion() = Constants.FLATBUFFERS_23_1_20()
|
||||||
fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal())
|
fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal())
|
||||||
fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal {
|
fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal {
|
||||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ FetchContent_MakeAvailable(
|
|||||||
googlebenchmark
|
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_FB_BENCH_DIR ${CPP_BENCH_DIR}/flatbuffers)
|
||||||
set(CPP_RAW_BENCH_DIR ${CPP_BENCH_DIR}/raw)
|
set(CPP_RAW_BENCH_DIR ${CPP_BENCH_DIR}/raw)
|
||||||
set(CPP_BENCH_FBS ${CPP_FB_BENCH_DIR}/bench.fbs)
|
set(CPP_BENCH_FBS ${CPP_FB_BENCH_DIR}/bench.fbs)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class BitWidthUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static BitWidth width(num value) {
|
static BitWidth width(num value) {
|
||||||
if (value.toInt() == value) {
|
if (value is int) {
|
||||||
var v = value.toInt().abs();
|
var v = value.toInt().abs();
|
||||||
if (v >> 7 == 0) return BitWidth.width8;
|
if (v >> 7 == 0) return BitWidth.width8;
|
||||||
if (v >> 15 == 0) return BitWidth.width16;
|
if (v >> 15 == 0) return BitWidth.width16;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: flat_buffers
|
name: flat_buffers
|
||||||
version: 22.10.26
|
version: 23.1.20
|
||||||
description: FlatBuffers reading and writing library for Dart. Based on original work by Konstantin Scheglov and Paul Berry of the Dart SDK team.
|
description: FlatBuffers reading and writing library for Dart. Based on original work by Konstantin Scheglov and Paul Berry of the Dart SDK team.
|
||||||
homepage: https://github.com/google/flatbuffers
|
homepage: https://github.com/google/flatbuffers
|
||||||
documentation: https://google.github.io/flatbuffers/index.html
|
documentation: https://google.github.io/flatbuffers/index.html
|
||||||
|
|||||||
207
dart/test/bool_structs_generated.dart
Normal file
207
dart/test/bool_structs_generated.dart
Normal file
@@ -0,0 +1,207 @@
|
|||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||||
|
|
||||||
|
import 'dart:typed_data' show Uint8List;
|
||||||
|
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||||
|
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
Foo._(this._bc, this._bcOffset);
|
||||||
|
factory Foo(List<int> bytes) {
|
||||||
|
final rootRef = fb.BufferContext.fromBytes(bytes);
|
||||||
|
return reader.read(rootRef, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const fb.Reader<Foo> reader = _FooReader();
|
||||||
|
|
||||||
|
final fb.BufferContext _bc;
|
||||||
|
final int _bcOffset;
|
||||||
|
|
||||||
|
FooProperties? get myFoo => FooProperties.reader.vTableGetNullable(_bc, _bcOffset, 4);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'Foo{myFoo: ${myFoo}}';
|
||||||
|
}
|
||||||
|
|
||||||
|
FooT unpack() => FooT(
|
||||||
|
myFoo: myFoo?.unpack());
|
||||||
|
|
||||||
|
static int pack(fb.Builder fbBuilder, FooT? object) {
|
||||||
|
if (object == null) return 0;
|
||||||
|
return object.pack(fbBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FooT implements fb.Packable {
|
||||||
|
FooPropertiesT? myFoo;
|
||||||
|
|
||||||
|
FooT({
|
||||||
|
this.myFoo});
|
||||||
|
|
||||||
|
@override
|
||||||
|
int pack(fb.Builder fbBuilder) {
|
||||||
|
fbBuilder.startTable(1);
|
||||||
|
if (myFoo != null) {
|
||||||
|
fbBuilder.addStruct(0, myFoo!.pack(fbBuilder));
|
||||||
|
}
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'FooT{myFoo: ${myFoo}}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FooReader extends fb.TableReader<Foo> {
|
||||||
|
const _FooReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Foo createObject(fb.BufferContext bc, int offset) =>
|
||||||
|
Foo._(bc, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
class FooBuilder {
|
||||||
|
FooBuilder(this.fbBuilder);
|
||||||
|
|
||||||
|
final fb.Builder fbBuilder;
|
||||||
|
|
||||||
|
void begin() {
|
||||||
|
fbBuilder.startTable(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int addMyFoo(int offset) {
|
||||||
|
fbBuilder.addStruct(0, offset);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
int finish() {
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FooObjectBuilder extends fb.ObjectBuilder {
|
||||||
|
final FooPropertiesObjectBuilder? _myFoo;
|
||||||
|
|
||||||
|
FooObjectBuilder({
|
||||||
|
FooPropertiesObjectBuilder? myFoo,
|
||||||
|
})
|
||||||
|
: _myFoo = myFoo;
|
||||||
|
|
||||||
|
/// Finish building, and store into the [fbBuilder].
|
||||||
|
@override
|
||||||
|
int finish(fb.Builder fbBuilder) {
|
||||||
|
fbBuilder.startTable(1);
|
||||||
|
if (_myFoo != null) {
|
||||||
|
fbBuilder.addStruct(0, _myFoo!.finish(fbBuilder));
|
||||||
|
}
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience method to serialize to byte list.
|
||||||
|
@override
|
||||||
|
Uint8List toBytes([String? fileIdentifier]) {
|
||||||
|
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||||
|
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||||
|
return fbBuilder.buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class FooProperties {
|
||||||
|
FooProperties._(this._bc, this._bcOffset);
|
||||||
|
|
||||||
|
static const fb.Reader<FooProperties> reader = _FooPropertiesReader();
|
||||||
|
|
||||||
|
final fb.BufferContext _bc;
|
||||||
|
final int _bcOffset;
|
||||||
|
|
||||||
|
bool get a => const fb.BoolReader().read(_bc, _bcOffset + 0);
|
||||||
|
bool get b => const fb.BoolReader().read(_bc, _bcOffset + 1);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'FooProperties{a: ${a}, b: ${b}}';
|
||||||
|
}
|
||||||
|
|
||||||
|
FooPropertiesT unpack() => FooPropertiesT(
|
||||||
|
a: a,
|
||||||
|
b: b);
|
||||||
|
|
||||||
|
static int pack(fb.Builder fbBuilder, FooPropertiesT? object) {
|
||||||
|
if (object == null) return 0;
|
||||||
|
return object.pack(fbBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FooPropertiesT implements fb.Packable {
|
||||||
|
bool a;
|
||||||
|
bool b;
|
||||||
|
|
||||||
|
FooPropertiesT({
|
||||||
|
required this.a,
|
||||||
|
required this.b});
|
||||||
|
|
||||||
|
@override
|
||||||
|
int pack(fb.Builder fbBuilder) {
|
||||||
|
fbBuilder.putBool(b);
|
||||||
|
fbBuilder.putBool(a);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'FooPropertiesT{a: ${a}, b: ${b}}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FooPropertiesReader extends fb.StructReader<FooProperties> {
|
||||||
|
const _FooPropertiesReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get size => 2;
|
||||||
|
|
||||||
|
@override
|
||||||
|
FooProperties createObject(fb.BufferContext bc, int offset) =>
|
||||||
|
FooProperties._(bc, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
class FooPropertiesBuilder {
|
||||||
|
FooPropertiesBuilder(this.fbBuilder);
|
||||||
|
|
||||||
|
final fb.Builder fbBuilder;
|
||||||
|
|
||||||
|
int finish(bool a, bool b) {
|
||||||
|
fbBuilder.putBool(b);
|
||||||
|
fbBuilder.putBool(a);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class FooPropertiesObjectBuilder extends fb.ObjectBuilder {
|
||||||
|
final bool _a;
|
||||||
|
final bool _b;
|
||||||
|
|
||||||
|
FooPropertiesObjectBuilder({
|
||||||
|
required bool a,
|
||||||
|
required bool b,
|
||||||
|
})
|
||||||
|
: _a = a,
|
||||||
|
_b = b;
|
||||||
|
|
||||||
|
/// Finish building, and store into the [fbBuilder].
|
||||||
|
@override
|
||||||
|
int finish(fb.Builder fbBuilder) {
|
||||||
|
fbBuilder.putBool(_b);
|
||||||
|
fbBuilder.putBool(_a);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience method to serialize to byte list.
|
||||||
|
@override
|
||||||
|
Uint8List toBytes([String? fileIdentifier]) {
|
||||||
|
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||||
|
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||||
|
return fbBuilder.buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -87,7 +87,10 @@ class CheckOtherLangaugesData {
|
|||||||
'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, '
|
'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, '
|
||||||
'nativeInline: null, '
|
'nativeInline: null, '
|
||||||
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||||
'longEnumNormalDefault: LongEnum{value: 2}}, '
|
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, '
|
||||||
|
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
|
||||||
|
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
|
||||||
|
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, '
|
||||||
'test4: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], '
|
'test4: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], '
|
||||||
'testarrayofstring: [test1, test2], testarrayoftables: null, '
|
'testarrayofstring: [test1, test2], testarrayoftables: null, '
|
||||||
'enemy: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
|
'enemy: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
|
||||||
@@ -110,7 +113,10 @@ class CheckOtherLangaugesData {
|
|||||||
'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, '
|
'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, '
|
||||||
'nativeInline: null, '
|
'nativeInline: null, '
|
||||||
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||||
'longEnumNormalDefault: LongEnum{value: 2}}, '
|
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, '
|
||||||
|
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
|
||||||
|
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
|
||||||
|
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, '
|
||||||
'testnestedflatbuffer: null, testempty: null, testbool: true, '
|
'testnestedflatbuffer: null, testempty: null, testbool: true, '
|
||||||
'testhashs32Fnv1: -579221183, testhashu32Fnv1: 3715746113, '
|
'testhashs32Fnv1: -579221183, testhashu32Fnv1: 3715746113, '
|
||||||
'testhashs64Fnv1: 7930699090847568257, '
|
'testhashs64Fnv1: 7930699090847568257, '
|
||||||
@@ -137,7 +143,10 @@ class CheckOtherLangaugesData {
|
|||||||
'miss, val: 0, count: 0}, Stat{id: hit, val: 10, count: 1}], '
|
'miss, val: 0, count: 0}, Stat{id: hit, val: 10, count: 1}], '
|
||||||
'nativeInline: Test{a: 1, b: 2}, '
|
'nativeInline: Test{a: 1, b: 2}, '
|
||||||
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||||
'longEnumNormalDefault: LongEnum{value: 2}}',
|
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, '
|
||||||
|
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
|
||||||
|
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
|
||||||
|
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,10 @@ void main() {
|
|||||||
flx.addInt(-1025);
|
flx.addInt(-1025);
|
||||||
expect(flx.finish(), [255, 251, 5, 2]);
|
expect(flx.finish(), [255, 251, 5, 2]);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
var builder = Builder()..addDouble(1.0);
|
||||||
|
expect(builder.finish(), [0, 0, 128, 63, 14, 4]);
|
||||||
|
}
|
||||||
{
|
{
|
||||||
var flx = Builder();
|
var flx = Builder();
|
||||||
flx.addDouble(0.1);
|
flx.addDouble(0.1);
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ void main() {
|
|||||||
// expect(FlxValue.fromBuffer(b([255, 255, 255, 255, 255, 255, 255, 255, 11, 8])).intValue, 18446744073709551615);
|
// expect(FlxValue.fromBuffer(b([255, 255, 255, 255, 255, 255, 255, 255, 11, 8])).intValue, 18446744073709551615);
|
||||||
});
|
});
|
||||||
test('double value', () {
|
test('double value', () {
|
||||||
|
expect(Reference.fromBuffer(b([0, 0, 128, 63, 14, 4])).doubleValue, 1.0);
|
||||||
expect(Reference.fromBuffer(b([0, 0, 144, 64, 14, 4])).doubleValue, 4.5);
|
expect(Reference.fromBuffer(b([0, 0, 144, 64, 14, 4])).doubleValue, 4.5);
|
||||||
expect(Reference.fromBuffer(b([205, 204, 204, 61, 14, 4])).doubleValue,
|
expect(Reference.fromBuffer(b([205, 204, 204, 61, 14, 4])).doubleValue,
|
||||||
closeTo(.1, .001));
|
closeTo(.1, .001));
|
||||||
|
|||||||
109
dart/test/include_test1_generated.dart
Normal file
109
dart/test/include_test1_generated.dart
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||||
|
|
||||||
|
import 'dart:typed_data' show Uint8List;
|
||||||
|
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||||
|
|
||||||
|
|
||||||
|
import './include_test2_my_game.other_name_space_generated.dart' as my_game_other_name_space;
|
||||||
|
|
||||||
|
class TableA {
|
||||||
|
TableA._(this._bc, this._bcOffset);
|
||||||
|
factory TableA(List<int> bytes) {
|
||||||
|
final rootRef = fb.BufferContext.fromBytes(bytes);
|
||||||
|
return reader.read(rootRef, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const fb.Reader<TableA> reader = _TableAReader();
|
||||||
|
|
||||||
|
final fb.BufferContext _bc;
|
||||||
|
final int _bcOffset;
|
||||||
|
|
||||||
|
my_game_other_name_space.TableB? get b => my_game_other_name_space.TableB.reader.vTableGetNullable(_bc, _bcOffset, 4);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'TableA{b: ${b}}';
|
||||||
|
}
|
||||||
|
|
||||||
|
TableAT unpack() => TableAT(
|
||||||
|
b: b?.unpack());
|
||||||
|
|
||||||
|
static int pack(fb.Builder fbBuilder, TableAT? object) {
|
||||||
|
if (object == null) return 0;
|
||||||
|
return object.pack(fbBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TableAT implements fb.Packable {
|
||||||
|
my_game_other_name_space.TableBT? b;
|
||||||
|
|
||||||
|
TableAT({
|
||||||
|
this.b});
|
||||||
|
|
||||||
|
@override
|
||||||
|
int pack(fb.Builder fbBuilder) {
|
||||||
|
final int? bOffset = b?.pack(fbBuilder);
|
||||||
|
fbBuilder.startTable(1);
|
||||||
|
fbBuilder.addOffset(0, bOffset);
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'TableAT{b: ${b}}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TableAReader extends fb.TableReader<TableA> {
|
||||||
|
const _TableAReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
TableA createObject(fb.BufferContext bc, int offset) =>
|
||||||
|
TableA._(bc, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
class TableABuilder {
|
||||||
|
TableABuilder(this.fbBuilder);
|
||||||
|
|
||||||
|
final fb.Builder fbBuilder;
|
||||||
|
|
||||||
|
void begin() {
|
||||||
|
fbBuilder.startTable(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int addBOffset(int? offset) {
|
||||||
|
fbBuilder.addOffset(0, offset);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
int finish() {
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TableAObjectBuilder extends fb.ObjectBuilder {
|
||||||
|
final my_game_other_name_space.TableBObjectBuilder? _b;
|
||||||
|
|
||||||
|
TableAObjectBuilder({
|
||||||
|
my_game_other_name_space.TableBObjectBuilder? b,
|
||||||
|
})
|
||||||
|
: _b = b;
|
||||||
|
|
||||||
|
/// Finish building, and store into the [fbBuilder].
|
||||||
|
@override
|
||||||
|
int finish(fb.Builder fbBuilder) {
|
||||||
|
final int? bOffset = _b?.getOrCreateOffset(fbBuilder);
|
||||||
|
fbBuilder.startTable(1);
|
||||||
|
fbBuilder.addOffset(0, bOffset);
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience method to serialize to byte list.
|
||||||
|
@override
|
||||||
|
Uint8List toBytes([String? fileIdentifier]) {
|
||||||
|
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||||
|
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||||
|
return fbBuilder.buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
241
dart/test/include_test2_my_game.other_name_space_generated.dart
Normal file
241
dart/test/include_test2_my_game.other_name_space_generated.dart
Normal file
@@ -0,0 +1,241 @@
|
|||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||||
|
|
||||||
|
library my_game.other_name_space;
|
||||||
|
|
||||||
|
import 'dart:typed_data' show Uint8List;
|
||||||
|
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||||
|
|
||||||
|
|
||||||
|
import './include_test1_generated.dart';
|
||||||
|
|
||||||
|
class FromInclude {
|
||||||
|
final int value;
|
||||||
|
const FromInclude._(this.value);
|
||||||
|
|
||||||
|
factory FromInclude.fromValue(int value) {
|
||||||
|
final result = values[value];
|
||||||
|
if (result == null) {
|
||||||
|
throw StateError('Invalid value $value for bit flag enum FromInclude');
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FromInclude? _createOrNull(int? value) =>
|
||||||
|
value == null ? null : FromInclude.fromValue(value);
|
||||||
|
|
||||||
|
static const int minValue = 0;
|
||||||
|
static const int maxValue = 0;
|
||||||
|
static bool containsValue(int value) => values.containsKey(value);
|
||||||
|
|
||||||
|
static const FromInclude IncludeVal = FromInclude._(0);
|
||||||
|
static const Map<int, FromInclude> values = {
|
||||||
|
0: IncludeVal};
|
||||||
|
|
||||||
|
static const fb.Reader<FromInclude> reader = _FromIncludeReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'FromInclude{value: $value}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FromIncludeReader extends fb.Reader<FromInclude> {
|
||||||
|
const _FromIncludeReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get size => 8;
|
||||||
|
|
||||||
|
@override
|
||||||
|
FromInclude read(fb.BufferContext bc, int offset) =>
|
||||||
|
FromInclude.fromValue(const fb.Int64Reader().read(bc, offset));
|
||||||
|
}
|
||||||
|
|
||||||
|
class Unused {
|
||||||
|
Unused._(this._bc, this._bcOffset);
|
||||||
|
|
||||||
|
static const fb.Reader<Unused> reader = _UnusedReader();
|
||||||
|
|
||||||
|
final fb.BufferContext _bc;
|
||||||
|
final int _bcOffset;
|
||||||
|
|
||||||
|
int get a => const fb.Int32Reader().read(_bc, _bcOffset + 0);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'Unused{a: ${a}}';
|
||||||
|
}
|
||||||
|
|
||||||
|
UnusedT unpack() => UnusedT(
|
||||||
|
a: a);
|
||||||
|
|
||||||
|
static int pack(fb.Builder fbBuilder, UnusedT? object) {
|
||||||
|
if (object == null) return 0;
|
||||||
|
return object.pack(fbBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class UnusedT implements fb.Packable {
|
||||||
|
int a;
|
||||||
|
|
||||||
|
UnusedT({
|
||||||
|
required this.a});
|
||||||
|
|
||||||
|
@override
|
||||||
|
int pack(fb.Builder fbBuilder) {
|
||||||
|
fbBuilder.putInt32(a);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'UnusedT{a: ${a}}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _UnusedReader extends fb.StructReader<Unused> {
|
||||||
|
const _UnusedReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get size => 4;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Unused createObject(fb.BufferContext bc, int offset) =>
|
||||||
|
Unused._(bc, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
class UnusedBuilder {
|
||||||
|
UnusedBuilder(this.fbBuilder);
|
||||||
|
|
||||||
|
final fb.Builder fbBuilder;
|
||||||
|
|
||||||
|
int finish(int a) {
|
||||||
|
fbBuilder.putInt32(a);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class UnusedObjectBuilder extends fb.ObjectBuilder {
|
||||||
|
final int _a;
|
||||||
|
|
||||||
|
UnusedObjectBuilder({
|
||||||
|
required int a,
|
||||||
|
})
|
||||||
|
: _a = a;
|
||||||
|
|
||||||
|
/// Finish building, and store into the [fbBuilder].
|
||||||
|
@override
|
||||||
|
int finish(fb.Builder fbBuilder) {
|
||||||
|
fbBuilder.putInt32(_a);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience method to serialize to byte list.
|
||||||
|
@override
|
||||||
|
Uint8List toBytes([String? fileIdentifier]) {
|
||||||
|
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||||
|
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||||
|
return fbBuilder.buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class TableB {
|
||||||
|
TableB._(this._bc, this._bcOffset);
|
||||||
|
factory TableB(List<int> bytes) {
|
||||||
|
final rootRef = fb.BufferContext.fromBytes(bytes);
|
||||||
|
return reader.read(rootRef, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const fb.Reader<TableB> reader = _TableBReader();
|
||||||
|
|
||||||
|
final fb.BufferContext _bc;
|
||||||
|
final int _bcOffset;
|
||||||
|
|
||||||
|
TableA? get a => TableA.reader.vTableGetNullable(_bc, _bcOffset, 4);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'TableB{a: ${a}}';
|
||||||
|
}
|
||||||
|
|
||||||
|
TableBT unpack() => TableBT(
|
||||||
|
a: a?.unpack());
|
||||||
|
|
||||||
|
static int pack(fb.Builder fbBuilder, TableBT? object) {
|
||||||
|
if (object == null) return 0;
|
||||||
|
return object.pack(fbBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TableBT implements fb.Packable {
|
||||||
|
TableAT? a;
|
||||||
|
|
||||||
|
TableBT({
|
||||||
|
this.a});
|
||||||
|
|
||||||
|
@override
|
||||||
|
int pack(fb.Builder fbBuilder) {
|
||||||
|
final int? aOffset = a?.pack(fbBuilder);
|
||||||
|
fbBuilder.startTable(1);
|
||||||
|
fbBuilder.addOffset(0, aOffset);
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'TableBT{a: ${a}}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TableBReader extends fb.TableReader<TableB> {
|
||||||
|
const _TableBReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
TableB createObject(fb.BufferContext bc, int offset) =>
|
||||||
|
TableB._(bc, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
class TableBBuilder {
|
||||||
|
TableBBuilder(this.fbBuilder);
|
||||||
|
|
||||||
|
final fb.Builder fbBuilder;
|
||||||
|
|
||||||
|
void begin() {
|
||||||
|
fbBuilder.startTable(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int addAOffset(int? offset) {
|
||||||
|
fbBuilder.addOffset(0, offset);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
int finish() {
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TableBObjectBuilder extends fb.ObjectBuilder {
|
||||||
|
final TableAObjectBuilder? _a;
|
||||||
|
|
||||||
|
TableBObjectBuilder({
|
||||||
|
TableAObjectBuilder? a,
|
||||||
|
})
|
||||||
|
: _a = a;
|
||||||
|
|
||||||
|
/// Finish building, and store into the [fbBuilder].
|
||||||
|
@override
|
||||||
|
int finish(fb.Builder fbBuilder) {
|
||||||
|
final int? aOffset = _a?.getOrCreateOffset(fbBuilder);
|
||||||
|
fbBuilder.startTable(1);
|
||||||
|
fbBuilder.addOffset(0, aOffset);
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience method to serialize to byte list.
|
||||||
|
@override
|
||||||
|
Uint8List toBytes([String? fileIdentifier]) {
|
||||||
|
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||||
|
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||||
|
return fbBuilder.buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -278,3 +278,122 @@ class KeywordsInTableObjectBuilder extends fb.ObjectBuilder {
|
|||||||
return fbBuilder.buffer;
|
return fbBuilder.buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class Table2 {
|
||||||
|
Table2._(this._bc, this._bcOffset);
|
||||||
|
factory Table2(List<int> bytes) {
|
||||||
|
final rootRef = fb.BufferContext.fromBytes(bytes);
|
||||||
|
return reader.read(rootRef, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const fb.Reader<Table2> reader = _Table2Reader();
|
||||||
|
|
||||||
|
final fb.BufferContext _bc;
|
||||||
|
final int _bcOffset;
|
||||||
|
|
||||||
|
KeywordsInUnionTypeId? get typeType => KeywordsInUnionTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 4));
|
||||||
|
dynamic get type {
|
||||||
|
switch (typeType?.value) {
|
||||||
|
case 1: return KeywordsInTable.reader.vTableGetNullable(_bc, _bcOffset, 6);
|
||||||
|
case 2: return KeywordsInTable.reader.vTableGetNullable(_bc, _bcOffset, 6);
|
||||||
|
default: return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'Table2{typeType: ${typeType}, type: ${type}}';
|
||||||
|
}
|
||||||
|
|
||||||
|
Table2T unpack() => Table2T(
|
||||||
|
typeType: typeType,
|
||||||
|
type: type);
|
||||||
|
|
||||||
|
static int pack(fb.Builder fbBuilder, Table2T? object) {
|
||||||
|
if (object == null) return 0;
|
||||||
|
return object.pack(fbBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Table2T implements fb.Packable {
|
||||||
|
KeywordsInUnionTypeId? typeType;
|
||||||
|
dynamic type;
|
||||||
|
|
||||||
|
Table2T({
|
||||||
|
this.typeType,
|
||||||
|
this.type});
|
||||||
|
|
||||||
|
@override
|
||||||
|
int pack(fb.Builder fbBuilder) {
|
||||||
|
final int? typeOffset = type?.pack(fbBuilder);
|
||||||
|
fbBuilder.startTable(2);
|
||||||
|
fbBuilder.addUint8(0, typeType?.value);
|
||||||
|
fbBuilder.addOffset(1, typeOffset);
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'Table2T{typeType: ${typeType}, type: ${type}}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _Table2Reader extends fb.TableReader<Table2> {
|
||||||
|
const _Table2Reader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Table2 createObject(fb.BufferContext bc, int offset) =>
|
||||||
|
Table2._(bc, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Table2Builder {
|
||||||
|
Table2Builder(this.fbBuilder);
|
||||||
|
|
||||||
|
final fb.Builder fbBuilder;
|
||||||
|
|
||||||
|
void begin() {
|
||||||
|
fbBuilder.startTable(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int addTypeType(KeywordsInUnionTypeId? typeType) {
|
||||||
|
fbBuilder.addUint8(0, typeType?.value);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
int addTypeOffset(int? offset) {
|
||||||
|
fbBuilder.addOffset(1, offset);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
int finish() {
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Table2ObjectBuilder extends fb.ObjectBuilder {
|
||||||
|
final KeywordsInUnionTypeId? _typeType;
|
||||||
|
final dynamic _type;
|
||||||
|
|
||||||
|
Table2ObjectBuilder({
|
||||||
|
KeywordsInUnionTypeId? typeType,
|
||||||
|
dynamic type,
|
||||||
|
})
|
||||||
|
: _typeType = typeType,
|
||||||
|
_type = type;
|
||||||
|
|
||||||
|
/// Finish building, and store into the [fbBuilder].
|
||||||
|
@override
|
||||||
|
int finish(fb.Builder fbBuilder) {
|
||||||
|
final int? typeOffset = _type?.getOrCreateOffset(fbBuilder);
|
||||||
|
fbBuilder.startTable(2);
|
||||||
|
fbBuilder.addUint8(0, _typeType?.value);
|
||||||
|
fbBuilder.addOffset(1, typeOffset);
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience method to serialize to byte list.
|
||||||
|
@override
|
||||||
|
Uint8List toBytes([String? fileIdentifier]) {
|
||||||
|
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||||
|
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||||
|
return fbBuilder.buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
155
dart/test/list_of_enums_generated.dart
Normal file
155
dart/test/list_of_enums_generated.dart
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||||
|
|
||||||
|
import 'dart:typed_data' show Uint8List;
|
||||||
|
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||||
|
|
||||||
|
|
||||||
|
class OptionsEnum {
|
||||||
|
final int value;
|
||||||
|
const OptionsEnum._(this.value);
|
||||||
|
|
||||||
|
factory OptionsEnum.fromValue(int value) {
|
||||||
|
final result = values[value];
|
||||||
|
if (result == null) {
|
||||||
|
throw StateError('Invalid value $value for bit flag enum OptionsEnum');
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static OptionsEnum? _createOrNull(int? value) =>
|
||||||
|
value == null ? null : OptionsEnum.fromValue(value);
|
||||||
|
|
||||||
|
static const int minValue = 1;
|
||||||
|
static const int maxValue = 3;
|
||||||
|
static bool containsValue(int value) => values.containsKey(value);
|
||||||
|
|
||||||
|
static const OptionsEnum A = OptionsEnum._(1);
|
||||||
|
static const OptionsEnum B = OptionsEnum._(2);
|
||||||
|
static const OptionsEnum C = OptionsEnum._(3);
|
||||||
|
static const Map<int, OptionsEnum> values = {
|
||||||
|
1: A,
|
||||||
|
2: B,
|
||||||
|
3: C};
|
||||||
|
|
||||||
|
static const fb.Reader<OptionsEnum> reader = _OptionsEnumReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'OptionsEnum{value: $value}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _OptionsEnumReader extends fb.Reader<OptionsEnum> {
|
||||||
|
const _OptionsEnumReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get size => 4;
|
||||||
|
|
||||||
|
@override
|
||||||
|
OptionsEnum read(fb.BufferContext bc, int offset) =>
|
||||||
|
OptionsEnum.fromValue(const fb.Uint32Reader().read(bc, offset));
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyTable {
|
||||||
|
MyTable._(this._bc, this._bcOffset);
|
||||||
|
factory MyTable(List<int> bytes) {
|
||||||
|
final rootRef = fb.BufferContext.fromBytes(bytes);
|
||||||
|
return reader.read(rootRef, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const fb.Reader<MyTable> reader = _MyTableReader();
|
||||||
|
|
||||||
|
final fb.BufferContext _bc;
|
||||||
|
final int _bcOffset;
|
||||||
|
|
||||||
|
List<OptionsEnum>? get options => const fb.ListReader<OptionsEnum>(OptionsEnum.reader).vTableGetNullable(_bc, _bcOffset, 4);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'MyTable{options: ${options}}';
|
||||||
|
}
|
||||||
|
|
||||||
|
MyTableT unpack() => MyTableT(
|
||||||
|
options: const fb.ListReader<OptionsEnum>(OptionsEnum.reader, lazy: false).vTableGetNullable(_bc, _bcOffset, 4));
|
||||||
|
|
||||||
|
static int pack(fb.Builder fbBuilder, MyTableT? object) {
|
||||||
|
if (object == null) return 0;
|
||||||
|
return object.pack(fbBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyTableT implements fb.Packable {
|
||||||
|
List<OptionsEnum>? options;
|
||||||
|
|
||||||
|
MyTableT({
|
||||||
|
this.options});
|
||||||
|
|
||||||
|
@override
|
||||||
|
int pack(fb.Builder fbBuilder) {
|
||||||
|
final int? optionsOffset = options == null ? null
|
||||||
|
: fbBuilder.writeListUint32(options!.map((f) => f.value).toList());
|
||||||
|
fbBuilder.startTable(1);
|
||||||
|
fbBuilder.addOffset(0, optionsOffset);
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'MyTableT{options: ${options}}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MyTableReader extends fb.TableReader<MyTable> {
|
||||||
|
const _MyTableReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
MyTable createObject(fb.BufferContext bc, int offset) =>
|
||||||
|
MyTable._(bc, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyTableBuilder {
|
||||||
|
MyTableBuilder(this.fbBuilder);
|
||||||
|
|
||||||
|
final fb.Builder fbBuilder;
|
||||||
|
|
||||||
|
void begin() {
|
||||||
|
fbBuilder.startTable(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int addOptionsOffset(int? offset) {
|
||||||
|
fbBuilder.addOffset(0, offset);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
int finish() {
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyTableObjectBuilder extends fb.ObjectBuilder {
|
||||||
|
final List<OptionsEnum>? _options;
|
||||||
|
|
||||||
|
MyTableObjectBuilder({
|
||||||
|
List<OptionsEnum>? options,
|
||||||
|
})
|
||||||
|
: _options = options;
|
||||||
|
|
||||||
|
/// Finish building, and store into the [fbBuilder].
|
||||||
|
@override
|
||||||
|
int finish(fb.Builder fbBuilder) {
|
||||||
|
final int? optionsOffset = _options == null ? null
|
||||||
|
: fbBuilder.writeListUint32(_options!.map((f) => f.value).toList());
|
||||||
|
fbBuilder.startTable(1);
|
||||||
|
fbBuilder.addOffset(0, optionsOffset);
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience method to serialize to byte list.
|
||||||
|
@override
|
||||||
|
Uint8List toBytes([String? fileIdentifier]) {
|
||||||
|
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||||
|
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||||
|
return fbBuilder.buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,6 +31,14 @@ enum Race:byte {
|
|||||||
Elf,
|
Elf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum LongEnum:ulong (bit_flags) {
|
||||||
|
LongOne = 1,
|
||||||
|
LongTwo = 2,
|
||||||
|
// Because this is a bitflag, 40 will be out of range of a 32-bit integer,
|
||||||
|
// allowing us to exercise any logic special to big numbers.
|
||||||
|
LongBig = 40,
|
||||||
|
}
|
||||||
|
|
||||||
union Any { Monster, TestSimpleTableWithEnum, MyGame.Example2.Monster }
|
union Any { Monster, TestSimpleTableWithEnum, MyGame.Example2.Monster }
|
||||||
|
|
||||||
union AnyUniqueAliases { M: Monster, TS: TestSimpleTableWithEnum, M2: MyGame.Example2.Monster }
|
union AnyUniqueAliases { M: Monster, TS: TestSimpleTableWithEnum, M2: MyGame.Example2.Monster }
|
||||||
@@ -62,6 +70,10 @@ struct StructOfStructs {
|
|||||||
c: Ability;
|
c: Ability;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct StructOfStructsOfStructs {
|
||||||
|
a: StructOfStructs;
|
||||||
|
}
|
||||||
|
|
||||||
table Stat {
|
table Stat {
|
||||||
id:string;
|
id:string;
|
||||||
val:long;
|
val:long;
|
||||||
@@ -124,6 +136,20 @@ table Monster {
|
|||||||
signed_enum:Race = None (id:48);
|
signed_enum:Race = None (id:48);
|
||||||
testrequirednestedflatbuffer:[ubyte] (id:49, nested_flatbuffer: "Monster");
|
testrequirednestedflatbuffer:[ubyte] (id:49, nested_flatbuffer: "Monster");
|
||||||
scalar_key_sorted_tables:[Stat] (id: 50);
|
scalar_key_sorted_tables:[Stat] (id: 50);
|
||||||
|
native_inline:Test (id: 51, native_inline);
|
||||||
|
// The default value of this enum will be a numeric zero, which isn't a valid
|
||||||
|
// enum value.
|
||||||
|
long_enum_non_enum_default:LongEnum (id: 52);
|
||||||
|
long_enum_normal_default:LongEnum = LongOne (id: 53);
|
||||||
|
// Test that default values nan and +/-inf work.
|
||||||
|
nan_default:float = nan (id: 54);
|
||||||
|
inf_default:float = inf (id: 55);
|
||||||
|
positive_inf_default:float = +inf (id: 56);
|
||||||
|
infinity_default:float = infinity (id: 57);
|
||||||
|
positive_infinity_default:float = +infinity (id: 58);
|
||||||
|
negative_inf_default:float = -inf (id: 59);
|
||||||
|
negative_infinity_default:float = -infinity (id: 60);
|
||||||
|
double_inf_default:double = inf (id: 61);
|
||||||
}
|
}
|
||||||
|
|
||||||
table TypeAliases {
|
table TypeAliases {
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import 'package:flat_buffers/flat_buffers.dart' as fb;
|
|||||||
import './monster_test_my_game_generated.dart' as my_game;
|
import './monster_test_my_game_generated.dart' as my_game;
|
||||||
import './monster_test_my_game.example_generated.dart' as my_game_example;
|
import './monster_test_my_game.example_generated.dart' as my_game_example;
|
||||||
|
|
||||||
|
import './include_test1_generated.dart';
|
||||||
|
|
||||||
class Monster {
|
class Monster {
|
||||||
Monster._(this._bc, this._bcOffset);
|
Monster._(this._bc, this._bcOffset);
|
||||||
factory Monster(List<int> bytes) {
|
factory Monster(List<int> bytes) {
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import 'package:flat_buffers/flat_buffers.dart' as fb;
|
|||||||
import './monster_test_my_game_generated.dart' as my_game;
|
import './monster_test_my_game_generated.dart' as my_game;
|
||||||
import './monster_test_my_game.example2_generated.dart' as my_game_example2;
|
import './monster_test_my_game.example2_generated.dart' as my_game_example2;
|
||||||
|
|
||||||
|
import './include_test1_generated.dart';
|
||||||
|
|
||||||
/// Composite components of Monster color.
|
/// Composite components of Monster color.
|
||||||
class Color {
|
class Color {
|
||||||
final int value;
|
final int value;
|
||||||
@@ -17,7 +19,11 @@ class Color {
|
|||||||
factory Color.fromValue(int value) {
|
factory Color.fromValue(int value) {
|
||||||
final result = values[value];
|
final result = values[value];
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
throw StateError('Invalid value $value for bit flag enum Color');
|
if (value == 0) {
|
||||||
|
return Color._(0);
|
||||||
|
} else {
|
||||||
|
throw StateError('Invalid value $value for bit flag enum Color');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -66,7 +72,7 @@ class Race {
|
|||||||
factory Race.fromValue(int value) {
|
factory Race.fromValue(int value) {
|
||||||
final result = values[value];
|
final result = values[value];
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
throw StateError('Invalid value $value for bit flag enum Race');
|
throw StateError('Invalid value $value for bit flag enum Race');
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -107,6 +113,54 @@ class _RaceReader extends fb.Reader<Race> {
|
|||||||
Race.fromValue(const fb.Int8Reader().read(bc, offset));
|
Race.fromValue(const fb.Int8Reader().read(bc, offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LongEnum {
|
||||||
|
final int value;
|
||||||
|
const LongEnum._(this.value);
|
||||||
|
|
||||||
|
factory LongEnum.fromValue(int value) {
|
||||||
|
final result = values[value];
|
||||||
|
if (result == null) {
|
||||||
|
if (value == 0) {
|
||||||
|
return LongEnum._(0);
|
||||||
|
} else {
|
||||||
|
throw StateError('Invalid value $value for bit flag enum LongEnum');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static LongEnum? _createOrNull(int? value) =>
|
||||||
|
value == null ? null : LongEnum.fromValue(value);
|
||||||
|
|
||||||
|
static bool containsValue(int value) => values.containsKey(value);
|
||||||
|
|
||||||
|
static const LongEnum LongOne = LongEnum._(2);
|
||||||
|
static const LongEnum LongTwo = LongEnum._(4);
|
||||||
|
static const LongEnum LongBig = LongEnum._(1099511627776);
|
||||||
|
static const Map<int, LongEnum> values = {
|
||||||
|
2: LongOne,
|
||||||
|
4: LongTwo,
|
||||||
|
1099511627776: LongBig};
|
||||||
|
|
||||||
|
static const fb.Reader<LongEnum> reader = _LongEnumReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'LongEnum{value: $value}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LongEnumReader extends fb.Reader<LongEnum> {
|
||||||
|
const _LongEnumReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get size => 8;
|
||||||
|
|
||||||
|
@override
|
||||||
|
LongEnum read(fb.BufferContext bc, int offset) =>
|
||||||
|
LongEnum.fromValue(const fb.Uint64Reader().read(bc, offset));
|
||||||
|
}
|
||||||
|
|
||||||
class AnyTypeId {
|
class AnyTypeId {
|
||||||
final int value;
|
final int value;
|
||||||
const AnyTypeId._(this.value);
|
const AnyTypeId._(this.value);
|
||||||
@@ -114,7 +168,7 @@ class AnyTypeId {
|
|||||||
factory AnyTypeId.fromValue(int value) {
|
factory AnyTypeId.fromValue(int value) {
|
||||||
final result = values[value];
|
final result = values[value];
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
throw StateError('Invalid value $value for bit flag enum AnyTypeId');
|
throw StateError('Invalid value $value for bit flag enum AnyTypeId');
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -162,7 +216,7 @@ class AnyUniqueAliasesTypeId {
|
|||||||
factory AnyUniqueAliasesTypeId.fromValue(int value) {
|
factory AnyUniqueAliasesTypeId.fromValue(int value) {
|
||||||
final result = values[value];
|
final result = values[value];
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
throw StateError('Invalid value $value for bit flag enum AnyUniqueAliasesTypeId');
|
throw StateError('Invalid value $value for bit flag enum AnyUniqueAliasesTypeId');
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -210,7 +264,7 @@ class AnyAmbiguousAliasesTypeId {
|
|||||||
factory AnyAmbiguousAliasesTypeId.fromValue(int value) {
|
factory AnyAmbiguousAliasesTypeId.fromValue(int value) {
|
||||||
final result = values[value];
|
final result = values[value];
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
throw StateError('Invalid value $value for bit flag enum AnyAmbiguousAliasesTypeId');
|
throw StateError('Invalid value $value for bit flag enum AnyAmbiguousAliasesTypeId');
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -264,7 +318,7 @@ class Test {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Test{a: $a, b: $b}';
|
return 'Test{a: ${a}, b: ${b}}';
|
||||||
}
|
}
|
||||||
|
|
||||||
TestT unpack() => TestT(
|
TestT unpack() => TestT(
|
||||||
@@ -295,7 +349,7 @@ class TestT implements fb.Packable {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'TestT{a: $a, b: $b}';
|
return 'TestT{a: ${a}, b: ${b}}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,7 +422,7 @@ class TestSimpleTableWithEnum {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'TestSimpleTableWithEnum{color: $color}';
|
return 'TestSimpleTableWithEnum{color: ${color}}';
|
||||||
}
|
}
|
||||||
|
|
||||||
TestSimpleTableWithEnumT unpack() => TestSimpleTableWithEnumT(
|
TestSimpleTableWithEnumT unpack() => TestSimpleTableWithEnumT(
|
||||||
@@ -395,7 +449,7 @@ class TestSimpleTableWithEnumT implements fb.Packable {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'TestSimpleTableWithEnumT{color: $color}';
|
return 'TestSimpleTableWithEnumT{color: ${color}}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -467,7 +521,7 @@ class Vec3 {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Vec3{x: $x, y: $y, z: $z, test1: $test1, test2: $test2, test3: $test3}';
|
return 'Vec3{x: ${x}, y: ${y}, z: ${z}, test1: ${test1}, test2: ${test2}, test3: ${test3}}';
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3T unpack() => Vec3T(
|
Vec3T unpack() => Vec3T(
|
||||||
@@ -516,7 +570,7 @@ class Vec3T implements fb.Packable {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Vec3T{x: $x, y: $y, z: $z, test1: $test1, test2: $test2, test3: $test3}';
|
return 'Vec3T{x: ${x}, y: ${y}, z: ${z}, test1: ${test1}, test2: ${test2}, test3: ${test3}}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -610,7 +664,7 @@ class Ability {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Ability{id: $id, distance: $distance}';
|
return 'Ability{id: ${id}, distance: ${distance}}';
|
||||||
}
|
}
|
||||||
|
|
||||||
AbilityT unpack() => AbilityT(
|
AbilityT unpack() => AbilityT(
|
||||||
@@ -640,7 +694,7 @@ class AbilityT implements fb.Packable {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'AbilityT{id: $id, distance: $distance}';
|
return 'AbilityT{id: ${id}, distance: ${distance}}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -709,7 +763,7 @@ class StructOfStructs {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'StructOfStructs{a: $a, b: $b, c: $c}';
|
return 'StructOfStructs{a: ${a}, b: ${b}, c: ${c}}';
|
||||||
}
|
}
|
||||||
|
|
||||||
StructOfStructsT unpack() => StructOfStructsT(
|
StructOfStructsT unpack() => StructOfStructsT(
|
||||||
@@ -743,7 +797,7 @@ class StructOfStructsT implements fb.Packable {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'StructOfStructsT{a: $a, b: $b, c: $c}';
|
return 'StructOfStructsT{a: ${a}, b: ${b}, c: ${c}}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -803,6 +857,94 @@ class StructOfStructsObjectBuilder extends fb.ObjectBuilder {
|
|||||||
return fbBuilder.buffer;
|
return fbBuilder.buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class StructOfStructsOfStructs {
|
||||||
|
StructOfStructsOfStructs._(this._bc, this._bcOffset);
|
||||||
|
|
||||||
|
static const fb.Reader<StructOfStructsOfStructs> reader = _StructOfStructsOfStructsReader();
|
||||||
|
|
||||||
|
final fb.BufferContext _bc;
|
||||||
|
final int _bcOffset;
|
||||||
|
|
||||||
|
StructOfStructs get a => StructOfStructs.reader.read(_bc, _bcOffset + 0);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'StructOfStructsOfStructs{a: ${a}}';
|
||||||
|
}
|
||||||
|
|
||||||
|
StructOfStructsOfStructsT unpack() => StructOfStructsOfStructsT(
|
||||||
|
a: a.unpack());
|
||||||
|
|
||||||
|
static int pack(fb.Builder fbBuilder, StructOfStructsOfStructsT? object) {
|
||||||
|
if (object == null) return 0;
|
||||||
|
return object.pack(fbBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class StructOfStructsOfStructsT implements fb.Packable {
|
||||||
|
StructOfStructsT a;
|
||||||
|
|
||||||
|
StructOfStructsOfStructsT({
|
||||||
|
required this.a});
|
||||||
|
|
||||||
|
@override
|
||||||
|
int pack(fb.Builder fbBuilder) {
|
||||||
|
a.pack(fbBuilder);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'StructOfStructsOfStructsT{a: ${a}}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _StructOfStructsOfStructsReader extends fb.StructReader<StructOfStructsOfStructs> {
|
||||||
|
const _StructOfStructsOfStructsReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get size => 20;
|
||||||
|
|
||||||
|
@override
|
||||||
|
StructOfStructsOfStructs createObject(fb.BufferContext bc, int offset) =>
|
||||||
|
StructOfStructsOfStructs._(bc, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
class StructOfStructsOfStructsBuilder {
|
||||||
|
StructOfStructsOfStructsBuilder(this.fbBuilder);
|
||||||
|
|
||||||
|
final fb.Builder fbBuilder;
|
||||||
|
|
||||||
|
int finish(fb.StructBuilder a) {
|
||||||
|
a();
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class StructOfStructsOfStructsObjectBuilder extends fb.ObjectBuilder {
|
||||||
|
final StructOfStructsObjectBuilder _a;
|
||||||
|
|
||||||
|
StructOfStructsOfStructsObjectBuilder({
|
||||||
|
required StructOfStructsObjectBuilder a,
|
||||||
|
})
|
||||||
|
: _a = a;
|
||||||
|
|
||||||
|
/// Finish building, and store into the [fbBuilder].
|
||||||
|
@override
|
||||||
|
int finish(fb.Builder fbBuilder) {
|
||||||
|
_a.finish(fbBuilder);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience method to serialize to byte list.
|
||||||
|
@override
|
||||||
|
Uint8List toBytes([String? fileIdentifier]) {
|
||||||
|
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||||
|
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||||
|
return fbBuilder.buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
class Stat {
|
class Stat {
|
||||||
Stat._(this._bc, this._bcOffset);
|
Stat._(this._bc, this._bcOffset);
|
||||||
factory Stat(List<int> bytes) {
|
factory Stat(List<int> bytes) {
|
||||||
@@ -821,7 +963,7 @@ class Stat {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Stat{id: $id, val: $val, count: $count}';
|
return 'Stat{id: ${id}, val: ${val}, count: ${count}}';
|
||||||
}
|
}
|
||||||
|
|
||||||
StatT unpack() => StatT(
|
StatT unpack() => StatT(
|
||||||
@@ -858,7 +1000,7 @@ class StatT implements fb.Packable {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'StatT{id: $id, val: $val, count: $count}';
|
return 'StatT{id: ${id}, val: ${val}, count: ${count}}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -947,7 +1089,7 @@ class Referrable {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Referrable{id: $id}';
|
return 'Referrable{id: ${id}}';
|
||||||
}
|
}
|
||||||
|
|
||||||
ReferrableT unpack() => ReferrableT(
|
ReferrableT unpack() => ReferrableT(
|
||||||
@@ -974,7 +1116,7 @@ class ReferrableT implements fb.Packable {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'ReferrableT{id: $id}';
|
return 'ReferrableT{id: ${id}}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1115,10 +1257,21 @@ class Monster {
|
|||||||
Race get signedEnum => Race.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 100, -1));
|
Race get signedEnum => Race.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 100, -1));
|
||||||
List<int>? get testrequirednestedflatbuffer => const fb.Uint8ListReader().vTableGetNullable(_bc, _bcOffset, 102);
|
List<int>? get testrequirednestedflatbuffer => const fb.Uint8ListReader().vTableGetNullable(_bc, _bcOffset, 102);
|
||||||
List<Stat>? get scalarKeySortedTables => const fb.ListReader<Stat>(Stat.reader).vTableGetNullable(_bc, _bcOffset, 104);
|
List<Stat>? get scalarKeySortedTables => const fb.ListReader<Stat>(Stat.reader).vTableGetNullable(_bc, _bcOffset, 104);
|
||||||
|
Test? get nativeInline => Test.reader.vTableGetNullable(_bc, _bcOffset, 106);
|
||||||
|
LongEnum get longEnumNonEnumDefault => LongEnum.fromValue(const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 108, 0));
|
||||||
|
LongEnum get longEnumNormalDefault => LongEnum.fromValue(const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 110, 2));
|
||||||
|
double get nanDefault => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 112, double.nan);
|
||||||
|
double get infDefault => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 114, double.infinity);
|
||||||
|
double get positiveInfDefault => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 116, double.infinity);
|
||||||
|
double get infinityDefault => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 118, double.infinity);
|
||||||
|
double get positiveInfinityDefault => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 120, double.infinity);
|
||||||
|
double get negativeInfDefault => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 122, double.negativeInfinity);
|
||||||
|
double get negativeInfinityDefault => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 124, double.negativeInfinity);
|
||||||
|
double get doubleInfDefault => const fb.Float64Reader().vTableGet(_bc, _bcOffset, 126, double.infinity);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Monster{pos: $pos, mana: $mana, hp: $hp, name: $name, inventory: $inventory, color: $color, testType: $testType, test: $test, test4: $test4, testarrayofstring: $testarrayofstring, testarrayoftables: $testarrayoftables, enemy: $enemy, testnestedflatbuffer: $testnestedflatbuffer, testempty: $testempty, testbool: $testbool, testhashs32Fnv1: $testhashs32Fnv1, testhashu32Fnv1: $testhashu32Fnv1, testhashs64Fnv1: $testhashs64Fnv1, testhashu64Fnv1: $testhashu64Fnv1, testhashs32Fnv1a: $testhashs32Fnv1a, testhashu32Fnv1a: $testhashu32Fnv1a, testhashs64Fnv1a: $testhashs64Fnv1a, testhashu64Fnv1a: $testhashu64Fnv1a, testarrayofbools: $testarrayofbools, testf: $testf, testf2: $testf2, testf3: $testf3, testarrayofstring2: $testarrayofstring2, testarrayofsortedstruct: $testarrayofsortedstruct, flex: $flex, test5: $test5, vectorOfLongs: $vectorOfLongs, vectorOfDoubles: $vectorOfDoubles, parentNamespaceTest: $parentNamespaceTest, vectorOfReferrables: $vectorOfReferrables, singleWeakReference: $singleWeakReference, vectorOfWeakReferences: $vectorOfWeakReferences, vectorOfStrongReferrables: $vectorOfStrongReferrables, coOwningReference: $coOwningReference, vectorOfCoOwningReferences: $vectorOfCoOwningReferences, nonOwningReference: $nonOwningReference, vectorOfNonOwningReferences: $vectorOfNonOwningReferences, anyUniqueType: $anyUniqueType, anyUnique: $anyUnique, anyAmbiguousType: $anyAmbiguousType, anyAmbiguous: $anyAmbiguous, vectorOfEnums: $vectorOfEnums, signedEnum: $signedEnum, testrequirednestedflatbuffer: $testrequirednestedflatbuffer, scalarKeySortedTables: $scalarKeySortedTables}';
|
return 'Monster{pos: ${pos}, mana: ${mana}, hp: ${hp}, name: ${name}, inventory: ${inventory}, color: ${color}, testType: ${testType}, test: ${test}, test4: ${test4}, testarrayofstring: ${testarrayofstring}, testarrayoftables: ${testarrayoftables}, enemy: ${enemy}, testnestedflatbuffer: ${testnestedflatbuffer}, testempty: ${testempty}, testbool: ${testbool}, testhashs32Fnv1: ${testhashs32Fnv1}, testhashu32Fnv1: ${testhashu32Fnv1}, testhashs64Fnv1: ${testhashs64Fnv1}, testhashu64Fnv1: ${testhashu64Fnv1}, testhashs32Fnv1a: ${testhashs32Fnv1a}, testhashu32Fnv1a: ${testhashu32Fnv1a}, testhashs64Fnv1a: ${testhashs64Fnv1a}, testhashu64Fnv1a: ${testhashu64Fnv1a}, testarrayofbools: ${testarrayofbools}, testf: ${testf}, testf2: ${testf2}, testf3: ${testf3}, testarrayofstring2: ${testarrayofstring2}, testarrayofsortedstruct: ${testarrayofsortedstruct}, flex: ${flex}, test5: ${test5}, vectorOfLongs: ${vectorOfLongs}, vectorOfDoubles: ${vectorOfDoubles}, parentNamespaceTest: ${parentNamespaceTest}, vectorOfReferrables: ${vectorOfReferrables}, singleWeakReference: ${singleWeakReference}, vectorOfWeakReferences: ${vectorOfWeakReferences}, vectorOfStrongReferrables: ${vectorOfStrongReferrables}, coOwningReference: ${coOwningReference}, vectorOfCoOwningReferences: ${vectorOfCoOwningReferences}, nonOwningReference: ${nonOwningReference}, vectorOfNonOwningReferences: ${vectorOfNonOwningReferences}, anyUniqueType: ${anyUniqueType}, anyUnique: ${anyUnique}, anyAmbiguousType: ${anyAmbiguousType}, anyAmbiguous: ${anyAmbiguous}, vectorOfEnums: ${vectorOfEnums}, signedEnum: ${signedEnum}, testrequirednestedflatbuffer: ${testrequirednestedflatbuffer}, scalarKeySortedTables: ${scalarKeySortedTables}, nativeInline: ${nativeInline}, longEnumNonEnumDefault: ${longEnumNonEnumDefault}, longEnumNormalDefault: ${longEnumNormalDefault}, nanDefault: ${nanDefault}, infDefault: ${infDefault}, positiveInfDefault: ${positiveInfDefault}, infinityDefault: ${infinityDefault}, positiveInfinityDefault: ${positiveInfinityDefault}, negativeInfDefault: ${negativeInfDefault}, negativeInfinityDefault: ${negativeInfinityDefault}, doubleInfDefault: ${doubleInfDefault}}';
|
||||||
}
|
}
|
||||||
|
|
||||||
MonsterT unpack() => MonsterT(
|
MonsterT unpack() => MonsterT(
|
||||||
@@ -1171,7 +1324,18 @@ class Monster {
|
|||||||
vectorOfEnums: const fb.ListReader<Color>(Color.reader, lazy: false).vTableGetNullable(_bc, _bcOffset, 98),
|
vectorOfEnums: const fb.ListReader<Color>(Color.reader, lazy: false).vTableGetNullable(_bc, _bcOffset, 98),
|
||||||
signedEnum: signedEnum,
|
signedEnum: signedEnum,
|
||||||
testrequirednestedflatbuffer: const fb.Uint8ListReader(lazy: false).vTableGetNullable(_bc, _bcOffset, 102),
|
testrequirednestedflatbuffer: const fb.Uint8ListReader(lazy: false).vTableGetNullable(_bc, _bcOffset, 102),
|
||||||
scalarKeySortedTables: scalarKeySortedTables?.map((e) => e.unpack()).toList());
|
scalarKeySortedTables: scalarKeySortedTables?.map((e) => e.unpack()).toList(),
|
||||||
|
nativeInline: nativeInline?.unpack(),
|
||||||
|
longEnumNonEnumDefault: longEnumNonEnumDefault,
|
||||||
|
longEnumNormalDefault: longEnumNormalDefault,
|
||||||
|
nanDefault: nanDefault,
|
||||||
|
infDefault: infDefault,
|
||||||
|
positiveInfDefault: positiveInfDefault,
|
||||||
|
infinityDefault: infinityDefault,
|
||||||
|
positiveInfinityDefault: positiveInfinityDefault,
|
||||||
|
negativeInfDefault: negativeInfDefault,
|
||||||
|
negativeInfinityDefault: negativeInfinityDefault,
|
||||||
|
doubleInfDefault: doubleInfDefault);
|
||||||
|
|
||||||
static int pack(fb.Builder fbBuilder, MonsterT? object) {
|
static int pack(fb.Builder fbBuilder, MonsterT? object) {
|
||||||
if (object == null) return 0;
|
if (object == null) return 0;
|
||||||
@@ -1233,6 +1397,17 @@ class MonsterT implements fb.Packable {
|
|||||||
Race signedEnum;
|
Race signedEnum;
|
||||||
List<int>? testrequirednestedflatbuffer;
|
List<int>? testrequirednestedflatbuffer;
|
||||||
List<StatT>? scalarKeySortedTables;
|
List<StatT>? scalarKeySortedTables;
|
||||||
|
TestT? nativeInline;
|
||||||
|
LongEnum longEnumNonEnumDefault;
|
||||||
|
LongEnum longEnumNormalDefault;
|
||||||
|
double nanDefault;
|
||||||
|
double infDefault;
|
||||||
|
double positiveInfDefault;
|
||||||
|
double infinityDefault;
|
||||||
|
double positiveInfinityDefault;
|
||||||
|
double negativeInfDefault;
|
||||||
|
double negativeInfinityDefault;
|
||||||
|
double doubleInfDefault;
|
||||||
|
|
||||||
MonsterT({
|
MonsterT({
|
||||||
this.pos,
|
this.pos,
|
||||||
@@ -1284,7 +1459,18 @@ class MonsterT implements fb.Packable {
|
|||||||
this.vectorOfEnums,
|
this.vectorOfEnums,
|
||||||
this.signedEnum = Race.None,
|
this.signedEnum = Race.None,
|
||||||
this.testrequirednestedflatbuffer,
|
this.testrequirednestedflatbuffer,
|
||||||
this.scalarKeySortedTables});
|
this.scalarKeySortedTables,
|
||||||
|
this.nativeInline,
|
||||||
|
this.longEnumNonEnumDefault = const LongEnum._(0),
|
||||||
|
this.longEnumNormalDefault = LongEnum.LongOne,
|
||||||
|
this.nanDefault = double.nan,
|
||||||
|
this.infDefault = double.infinity,
|
||||||
|
this.positiveInfDefault = double.infinity,
|
||||||
|
this.infinityDefault = double.infinity,
|
||||||
|
this.positiveInfinityDefault = double.infinity,
|
||||||
|
this.negativeInfDefault = double.negativeInfinity,
|
||||||
|
this.negativeInfinityDefault = double.negativeInfinity,
|
||||||
|
this.doubleInfDefault = double.infinity});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int pack(fb.Builder fbBuilder) {
|
int pack(fb.Builder fbBuilder) {
|
||||||
@@ -1345,7 +1531,7 @@ class MonsterT implements fb.Packable {
|
|||||||
: fbBuilder.writeListUint8(testrequirednestedflatbuffer!);
|
: fbBuilder.writeListUint8(testrequirednestedflatbuffer!);
|
||||||
final int? scalarKeySortedTablesOffset = scalarKeySortedTables == null ? null
|
final int? scalarKeySortedTablesOffset = scalarKeySortedTables == null ? null
|
||||||
: fbBuilder.writeList(scalarKeySortedTables!.map((b) => b.pack(fbBuilder)).toList());
|
: fbBuilder.writeList(scalarKeySortedTables!.map((b) => b.pack(fbBuilder)).toList());
|
||||||
fbBuilder.startTable(50);
|
fbBuilder.startTable(62);
|
||||||
if (pos != null) {
|
if (pos != null) {
|
||||||
fbBuilder.addStruct(0, pos!.pack(fbBuilder));
|
fbBuilder.addStruct(0, pos!.pack(fbBuilder));
|
||||||
}
|
}
|
||||||
@@ -1398,12 +1584,25 @@ class MonsterT implements fb.Packable {
|
|||||||
fbBuilder.addInt8(48, signedEnum.value);
|
fbBuilder.addInt8(48, signedEnum.value);
|
||||||
fbBuilder.addOffset(49, testrequirednestedflatbufferOffset);
|
fbBuilder.addOffset(49, testrequirednestedflatbufferOffset);
|
||||||
fbBuilder.addOffset(50, scalarKeySortedTablesOffset);
|
fbBuilder.addOffset(50, scalarKeySortedTablesOffset);
|
||||||
|
if (nativeInline != null) {
|
||||||
|
fbBuilder.addStruct(51, nativeInline!.pack(fbBuilder));
|
||||||
|
}
|
||||||
|
fbBuilder.addUint64(52, longEnumNonEnumDefault.value);
|
||||||
|
fbBuilder.addUint64(53, longEnumNormalDefault.value);
|
||||||
|
fbBuilder.addFloat32(54, nanDefault);
|
||||||
|
fbBuilder.addFloat32(55, infDefault);
|
||||||
|
fbBuilder.addFloat32(56, positiveInfDefault);
|
||||||
|
fbBuilder.addFloat32(57, infinityDefault);
|
||||||
|
fbBuilder.addFloat32(58, positiveInfinityDefault);
|
||||||
|
fbBuilder.addFloat32(59, negativeInfDefault);
|
||||||
|
fbBuilder.addFloat32(60, negativeInfinityDefault);
|
||||||
|
fbBuilder.addFloat64(61, doubleInfDefault);
|
||||||
return fbBuilder.endTable();
|
return fbBuilder.endTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'MonsterT{pos: $pos, mana: $mana, hp: $hp, name: $name, inventory: $inventory, color: $color, testType: $testType, test: $test, test4: $test4, testarrayofstring: $testarrayofstring, testarrayoftables: $testarrayoftables, enemy: $enemy, testnestedflatbuffer: $testnestedflatbuffer, testempty: $testempty, testbool: $testbool, testhashs32Fnv1: $testhashs32Fnv1, testhashu32Fnv1: $testhashu32Fnv1, testhashs64Fnv1: $testhashs64Fnv1, testhashu64Fnv1: $testhashu64Fnv1, testhashs32Fnv1a: $testhashs32Fnv1a, testhashu32Fnv1a: $testhashu32Fnv1a, testhashs64Fnv1a: $testhashs64Fnv1a, testhashu64Fnv1a: $testhashu64Fnv1a, testarrayofbools: $testarrayofbools, testf: $testf, testf2: $testf2, testf3: $testf3, testarrayofstring2: $testarrayofstring2, testarrayofsortedstruct: $testarrayofsortedstruct, flex: $flex, test5: $test5, vectorOfLongs: $vectorOfLongs, vectorOfDoubles: $vectorOfDoubles, parentNamespaceTest: $parentNamespaceTest, vectorOfReferrables: $vectorOfReferrables, singleWeakReference: $singleWeakReference, vectorOfWeakReferences: $vectorOfWeakReferences, vectorOfStrongReferrables: $vectorOfStrongReferrables, coOwningReference: $coOwningReference, vectorOfCoOwningReferences: $vectorOfCoOwningReferences, nonOwningReference: $nonOwningReference, vectorOfNonOwningReferences: $vectorOfNonOwningReferences, anyUniqueType: $anyUniqueType, anyUnique: $anyUnique, anyAmbiguousType: $anyAmbiguousType, anyAmbiguous: $anyAmbiguous, vectorOfEnums: $vectorOfEnums, signedEnum: $signedEnum, testrequirednestedflatbuffer: $testrequirednestedflatbuffer, scalarKeySortedTables: $scalarKeySortedTables}';
|
return 'MonsterT{pos: ${pos}, mana: ${mana}, hp: ${hp}, name: ${name}, inventory: ${inventory}, color: ${color}, testType: ${testType}, test: ${test}, test4: ${test4}, testarrayofstring: ${testarrayofstring}, testarrayoftables: ${testarrayoftables}, enemy: ${enemy}, testnestedflatbuffer: ${testnestedflatbuffer}, testempty: ${testempty}, testbool: ${testbool}, testhashs32Fnv1: ${testhashs32Fnv1}, testhashu32Fnv1: ${testhashu32Fnv1}, testhashs64Fnv1: ${testhashs64Fnv1}, testhashu64Fnv1: ${testhashu64Fnv1}, testhashs32Fnv1a: ${testhashs32Fnv1a}, testhashu32Fnv1a: ${testhashu32Fnv1a}, testhashs64Fnv1a: ${testhashs64Fnv1a}, testhashu64Fnv1a: ${testhashu64Fnv1a}, testarrayofbools: ${testarrayofbools}, testf: ${testf}, testf2: ${testf2}, testf3: ${testf3}, testarrayofstring2: ${testarrayofstring2}, testarrayofsortedstruct: ${testarrayofsortedstruct}, flex: ${flex}, test5: ${test5}, vectorOfLongs: ${vectorOfLongs}, vectorOfDoubles: ${vectorOfDoubles}, parentNamespaceTest: ${parentNamespaceTest}, vectorOfReferrables: ${vectorOfReferrables}, singleWeakReference: ${singleWeakReference}, vectorOfWeakReferences: ${vectorOfWeakReferences}, vectorOfStrongReferrables: ${vectorOfStrongReferrables}, coOwningReference: ${coOwningReference}, vectorOfCoOwningReferences: ${vectorOfCoOwningReferences}, nonOwningReference: ${nonOwningReference}, vectorOfNonOwningReferences: ${vectorOfNonOwningReferences}, anyUniqueType: ${anyUniqueType}, anyUnique: ${anyUnique}, anyAmbiguousType: ${anyAmbiguousType}, anyAmbiguous: ${anyAmbiguous}, vectorOfEnums: ${vectorOfEnums}, signedEnum: ${signedEnum}, testrequirednestedflatbuffer: ${testrequirednestedflatbuffer}, scalarKeySortedTables: ${scalarKeySortedTables}, nativeInline: ${nativeInline}, longEnumNonEnumDefault: ${longEnumNonEnumDefault}, longEnumNormalDefault: ${longEnumNormalDefault}, nanDefault: ${nanDefault}, infDefault: ${infDefault}, positiveInfDefault: ${positiveInfDefault}, infinityDefault: ${infinityDefault}, positiveInfinityDefault: ${positiveInfinityDefault}, negativeInfDefault: ${negativeInfDefault}, negativeInfinityDefault: ${negativeInfinityDefault}, doubleInfDefault: ${doubleInfDefault}}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1421,7 +1620,7 @@ class MonsterBuilder {
|
|||||||
final fb.Builder fbBuilder;
|
final fb.Builder fbBuilder;
|
||||||
|
|
||||||
void begin() {
|
void begin() {
|
||||||
fbBuilder.startTable(50);
|
fbBuilder.startTable(62);
|
||||||
}
|
}
|
||||||
|
|
||||||
int addPos(int offset) {
|
int addPos(int offset) {
|
||||||
@@ -1624,6 +1823,50 @@ class MonsterBuilder {
|
|||||||
fbBuilder.addOffset(50, offset);
|
fbBuilder.addOffset(50, offset);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
|
int addNativeInline(int offset) {
|
||||||
|
fbBuilder.addStruct(51, offset);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
int addLongEnumNonEnumDefault(LongEnum? longEnumNonEnumDefault) {
|
||||||
|
fbBuilder.addUint64(52, longEnumNonEnumDefault?.value);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
int addLongEnumNormalDefault(LongEnum? longEnumNormalDefault) {
|
||||||
|
fbBuilder.addUint64(53, longEnumNormalDefault?.value);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
int addNanDefault(double? nanDefault) {
|
||||||
|
fbBuilder.addFloat32(54, nanDefault);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
int addInfDefault(double? infDefault) {
|
||||||
|
fbBuilder.addFloat32(55, infDefault);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
int addPositiveInfDefault(double? positiveInfDefault) {
|
||||||
|
fbBuilder.addFloat32(56, positiveInfDefault);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
int addInfinityDefault(double? infinityDefault) {
|
||||||
|
fbBuilder.addFloat32(57, infinityDefault);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
int addPositiveInfinityDefault(double? positiveInfinityDefault) {
|
||||||
|
fbBuilder.addFloat32(58, positiveInfinityDefault);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
int addNegativeInfDefault(double? negativeInfDefault) {
|
||||||
|
fbBuilder.addFloat32(59, negativeInfDefault);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
int addNegativeInfinityDefault(double? negativeInfinityDefault) {
|
||||||
|
fbBuilder.addFloat32(60, negativeInfinityDefault);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
int addDoubleInfDefault(double? doubleInfDefault) {
|
||||||
|
fbBuilder.addFloat64(61, doubleInfDefault);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
|
||||||
int finish() {
|
int finish() {
|
||||||
return fbBuilder.endTable();
|
return fbBuilder.endTable();
|
||||||
@@ -1681,6 +1924,17 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||||||
final Race? _signedEnum;
|
final Race? _signedEnum;
|
||||||
final List<int>? _testrequirednestedflatbuffer;
|
final List<int>? _testrequirednestedflatbuffer;
|
||||||
final List<StatObjectBuilder>? _scalarKeySortedTables;
|
final List<StatObjectBuilder>? _scalarKeySortedTables;
|
||||||
|
final TestObjectBuilder? _nativeInline;
|
||||||
|
final LongEnum? _longEnumNonEnumDefault;
|
||||||
|
final LongEnum? _longEnumNormalDefault;
|
||||||
|
final double? _nanDefault;
|
||||||
|
final double? _infDefault;
|
||||||
|
final double? _positiveInfDefault;
|
||||||
|
final double? _infinityDefault;
|
||||||
|
final double? _positiveInfinityDefault;
|
||||||
|
final double? _negativeInfDefault;
|
||||||
|
final double? _negativeInfinityDefault;
|
||||||
|
final double? _doubleInfDefault;
|
||||||
|
|
||||||
MonsterObjectBuilder({
|
MonsterObjectBuilder({
|
||||||
Vec3ObjectBuilder? pos,
|
Vec3ObjectBuilder? pos,
|
||||||
@@ -1733,6 +1987,17 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||||||
Race? signedEnum,
|
Race? signedEnum,
|
||||||
List<int>? testrequirednestedflatbuffer,
|
List<int>? testrequirednestedflatbuffer,
|
||||||
List<StatObjectBuilder>? scalarKeySortedTables,
|
List<StatObjectBuilder>? scalarKeySortedTables,
|
||||||
|
TestObjectBuilder? nativeInline,
|
||||||
|
LongEnum? longEnumNonEnumDefault,
|
||||||
|
LongEnum? longEnumNormalDefault,
|
||||||
|
double? nanDefault,
|
||||||
|
double? infDefault,
|
||||||
|
double? positiveInfDefault,
|
||||||
|
double? infinityDefault,
|
||||||
|
double? positiveInfinityDefault,
|
||||||
|
double? negativeInfDefault,
|
||||||
|
double? negativeInfinityDefault,
|
||||||
|
double? doubleInfDefault,
|
||||||
})
|
})
|
||||||
: _pos = pos,
|
: _pos = pos,
|
||||||
_mana = mana,
|
_mana = mana,
|
||||||
@@ -1783,7 +2048,18 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||||||
_vectorOfEnums = vectorOfEnums,
|
_vectorOfEnums = vectorOfEnums,
|
||||||
_signedEnum = signedEnum,
|
_signedEnum = signedEnum,
|
||||||
_testrequirednestedflatbuffer = testrequirednestedflatbuffer,
|
_testrequirednestedflatbuffer = testrequirednestedflatbuffer,
|
||||||
_scalarKeySortedTables = scalarKeySortedTables;
|
_scalarKeySortedTables = scalarKeySortedTables,
|
||||||
|
_nativeInline = nativeInline,
|
||||||
|
_longEnumNonEnumDefault = longEnumNonEnumDefault,
|
||||||
|
_longEnumNormalDefault = longEnumNormalDefault,
|
||||||
|
_nanDefault = nanDefault,
|
||||||
|
_infDefault = infDefault,
|
||||||
|
_positiveInfDefault = positiveInfDefault,
|
||||||
|
_infinityDefault = infinityDefault,
|
||||||
|
_positiveInfinityDefault = positiveInfinityDefault,
|
||||||
|
_negativeInfDefault = negativeInfDefault,
|
||||||
|
_negativeInfinityDefault = negativeInfinityDefault,
|
||||||
|
_doubleInfDefault = doubleInfDefault;
|
||||||
|
|
||||||
/// Finish building, and store into the [fbBuilder].
|
/// Finish building, and store into the [fbBuilder].
|
||||||
@override
|
@override
|
||||||
@@ -1836,7 +2112,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||||||
: fbBuilder.writeListUint8(_testrequirednestedflatbuffer!);
|
: fbBuilder.writeListUint8(_testrequirednestedflatbuffer!);
|
||||||
final int? scalarKeySortedTablesOffset = _scalarKeySortedTables == null ? null
|
final int? scalarKeySortedTablesOffset = _scalarKeySortedTables == null ? null
|
||||||
: fbBuilder.writeList(_scalarKeySortedTables!.map((b) => b.getOrCreateOffset(fbBuilder)).toList());
|
: fbBuilder.writeList(_scalarKeySortedTables!.map((b) => b.getOrCreateOffset(fbBuilder)).toList());
|
||||||
fbBuilder.startTable(50);
|
fbBuilder.startTable(62);
|
||||||
if (_pos != null) {
|
if (_pos != null) {
|
||||||
fbBuilder.addStruct(0, _pos!.finish(fbBuilder));
|
fbBuilder.addStruct(0, _pos!.finish(fbBuilder));
|
||||||
}
|
}
|
||||||
@@ -1889,6 +2165,19 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||||||
fbBuilder.addInt8(48, _signedEnum?.value);
|
fbBuilder.addInt8(48, _signedEnum?.value);
|
||||||
fbBuilder.addOffset(49, testrequirednestedflatbufferOffset);
|
fbBuilder.addOffset(49, testrequirednestedflatbufferOffset);
|
||||||
fbBuilder.addOffset(50, scalarKeySortedTablesOffset);
|
fbBuilder.addOffset(50, scalarKeySortedTablesOffset);
|
||||||
|
if (_nativeInline != null) {
|
||||||
|
fbBuilder.addStruct(51, _nativeInline!.finish(fbBuilder));
|
||||||
|
}
|
||||||
|
fbBuilder.addUint64(52, _longEnumNonEnumDefault?.value);
|
||||||
|
fbBuilder.addUint64(53, _longEnumNormalDefault?.value);
|
||||||
|
fbBuilder.addFloat32(54, _nanDefault);
|
||||||
|
fbBuilder.addFloat32(55, _infDefault);
|
||||||
|
fbBuilder.addFloat32(56, _positiveInfDefault);
|
||||||
|
fbBuilder.addFloat32(57, _infinityDefault);
|
||||||
|
fbBuilder.addFloat32(58, _positiveInfinityDefault);
|
||||||
|
fbBuilder.addFloat32(59, _negativeInfDefault);
|
||||||
|
fbBuilder.addFloat32(60, _negativeInfinityDefault);
|
||||||
|
fbBuilder.addFloat64(61, _doubleInfDefault);
|
||||||
return fbBuilder.endTable();
|
return fbBuilder.endTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1927,7 +2216,7 @@ class TypeAliases {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'TypeAliases{i8: $i8, u8: $u8, i16: $i16, u16: $u16, i32: $i32, u32: $u32, i64: $i64, u64: $u64, f32: $f32, f64: $f64, v8: $v8, vf64: $vf64}';
|
return 'TypeAliases{i8: ${i8}, u8: ${u8}, i16: ${i16}, u16: ${u16}, i32: ${i32}, u32: ${u32}, i64: ${i64}, u64: ${u64}, f32: ${f32}, f64: ${f64}, v8: ${v8}, vf64: ${vf64}}';
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeAliasesT unpack() => TypeAliasesT(
|
TypeAliasesT unpack() => TypeAliasesT(
|
||||||
@@ -2002,7 +2291,7 @@ class TypeAliasesT implements fb.Packable {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'TypeAliasesT{i8: $i8, u8: $u8, i16: $i16, u16: $u16, i32: $i32, u32: $u32, i64: $i64, u64: $u64, f32: $f32, f64: $f64, v8: $v8, vf64: $vf64}';
|
return 'TypeAliasesT{i8: ${i8}, u8: ${u8}, i16: ${i16}, u16: ${u16}, i32: ${i32}, u32: ${u32}, i64: ${i64}, u64: ${u64}, f32: ${f32}, f64: ${f64}, v8: ${v8}, vf64: ${vf64}}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import 'package:flat_buffers/flat_buffers.dart' as fb;
|
|||||||
import './monster_test_my_game.example_generated.dart' as my_game_example;
|
import './monster_test_my_game.example_generated.dart' as my_game_example;
|
||||||
import './monster_test_my_game.example2_generated.dart' as my_game_example2;
|
import './monster_test_my_game.example2_generated.dart' as my_game_example2;
|
||||||
|
|
||||||
|
import './include_test1_generated.dart';
|
||||||
|
|
||||||
class InParentNamespace {
|
class InParentNamespace {
|
||||||
InParentNamespace._(this._bc, this._bcOffset);
|
InParentNamespace._(this._bc, this._bcOffset);
|
||||||
factory InParentNamespace(List<int> bytes) {
|
factory InParentNamespace(List<int> bytes) {
|
||||||
|
|||||||
Binary file not shown.
@@ -91,6 +91,9 @@ Additional options:
|
|||||||
- `--scoped-enums` : Use C++11 style scoped and strongly typed enums in
|
- `--scoped-enums` : Use C++11 style scoped and strongly typed enums in
|
||||||
generated C++. This also implies `--no-prefix`.
|
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.
|
- `--gen-includes` : (deprecated), this is the default behavior.
|
||||||
If the original behavior is required (no include
|
If the original behavior is required (no include
|
||||||
statements) use `--no-includes.`
|
statements) use `--no-includes.`
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ pass to the `GetRootAsMyRootType` function:
|
|||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
|
||||||
using MyGame.Example;
|
using MyGame.Example;
|
||||||
using FlatBuffers;
|
using Google.FlatBuffers;
|
||||||
|
|
||||||
// This snippet ignores exceptions for brevity.
|
// This snippet ignores exceptions for brevity.
|
||||||
byte[] data = File.ReadAllBytes("monsterdata_test.mon");
|
byte[] data = File.ReadAllBytes("monsterdata_test.mon");
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ To generate the docs for FlatBuffers from the source files, you
|
|||||||
will first need to install two programs.
|
will first need to install two programs.
|
||||||
|
|
||||||
1. You will need to install `doxygen`. See
|
1. You will need to install `doxygen`. See
|
||||||
[Download Doxygen](http://www.stack.nl/~dimitri/doxygen/download.html).
|
[Download Doxygen](https://doxygen.nl/download.html).
|
||||||
|
|
||||||
2. You will need to install `doxypypy` to format python comments appropriately.
|
2. You will need to install `doxypypy` to format python comments appropriately.
|
||||||
Install it from [here](https://github.com/Feneric/doxypypy).
|
Install it from [here](https://github.com/Feneric/doxypypy).
|
||||||
|
|||||||
@@ -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.
|
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}
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.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) {
|
if !monster.mutate(hp: 10) {
|
||||||
fatalError("couldn't mutate")
|
fatalError("couldn't mutate")
|
||||||
|
|||||||
@@ -415,7 +415,7 @@ The first step is to import/include the library, generated files, etc.
|
|||||||
</div>
|
</div>
|
||||||
<div class="language-csharp">
|
<div class="language-csharp">
|
||||||
~~~{.cs}
|
~~~{.cs}
|
||||||
using FlatBuffers;
|
using Google.FlatBuffers;
|
||||||
using MyGame.Sample; // The `flatc` generated files. (Monster, Vec3, etc.)
|
using MyGame.Sample; // The `flatc` generated files. (Monster, Vec3, etc.)
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
@@ -2200,7 +2200,7 @@ before:
|
|||||||
</div>
|
</div>
|
||||||
<div class="language-csharp">
|
<div class="language-csharp">
|
||||||
~~~{.cs}
|
~~~{.cs}
|
||||||
using FlatBuffers;
|
using Google.FlatBuffers;
|
||||||
using MyGame.Sample; // The `flatc` generated files. (Monster, Vec3, etc.)
|
using MyGame.Sample; // The `flatc` generated files. (Monster, Vec3, etc.)
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
@@ -2472,10 +2472,10 @@ myGame.Monster monster = new myGame.Monster(data);
|
|||||||
<div class="language-swift">
|
<div class="language-swift">
|
||||||
~~~{.swift}
|
~~~{.swift}
|
||||||
// create a ByteBuffer(:) from an [UInt8] or Data()
|
// 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.
|
// 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>
|
</div>
|
||||||
|
|
||||||
@@ -3449,7 +3449,7 @@ Java supports vectors of unions, but it isn't currently documented.
|
|||||||
</div>
|
</div>
|
||||||
<div class="language-csharp">
|
<div class="language-csharp">
|
||||||
~~~{.cs}
|
~~~{.cs}
|
||||||
using FlatBuffers;
|
using Google.FlatBuffers;
|
||||||
using Example.VectorOfUnions;
|
using Example.VectorOfUnions;
|
||||||
|
|
||||||
var fbb = new FlatBufferBuilder(100);
|
var fbb = new FlatBufferBuilder(100);
|
||||||
|
|||||||
27
examples/go-echo/README.md
Normal file
27
examples/go-echo/README.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Go Echo Example
|
||||||
|
|
||||||
|
A simple example demonstrating how to send flatbuffers over the network in Go.
|
||||||
|
|
||||||
|
## Generate flatbuffer code
|
||||||
|
|
||||||
|
```
|
||||||
|
flatc -g --gen-object-api --go-module-name echo hero.fbs net.fbs
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running example
|
||||||
|
|
||||||
|
1. Run go mod tidy to get dependencies
|
||||||
|
```
|
||||||
|
go mod tidy
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Start a server
|
||||||
|
```
|
||||||
|
go run server/server.go
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Run the client in another terminal
|
||||||
|
```
|
||||||
|
go run client/client.go
|
||||||
|
```
|
||||||
|
|
||||||
51
examples/go-echo/client/client.go
Normal file
51
examples/go-echo/client/client.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"echo/hero"
|
||||||
|
"echo/net"
|
||||||
|
|
||||||
|
flatbuffers "github.com/google/flatbuffers/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RequestBody() *bytes.Reader {
|
||||||
|
b := flatbuffers.NewBuilder(0)
|
||||||
|
r := net.RequestT{Player: &hero.WarriorT{Name: "Krull", Hp: 100}}
|
||||||
|
b.Finish(r.Pack(b))
|
||||||
|
return bytes.NewReader(b.FinishedBytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadResponse(r *http.Response) {
|
||||||
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Unable to read request body: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res := net.GetRootAsResponse(body, 0)
|
||||||
|
player := res.Player(nil)
|
||||||
|
|
||||||
|
fmt.Printf("Got response (name: %v, hp: %v)\n", string(player.Name()), player.Hp())
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
body := RequestBody()
|
||||||
|
req, err := http.NewRequest("POST", "http://localhost:8080/echo", body)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
client := http.DefaultClient
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ReadResponse(resp)
|
||||||
|
}
|
||||||
5
examples/go-echo/go.mod
Normal file
5
examples/go-echo/go.mod
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module echo
|
||||||
|
|
||||||
|
go 1.19
|
||||||
|
|
||||||
|
require github.com/google/flatbuffers v22.10.26+incompatible
|
||||||
6
examples/go-echo/hero.fbs
Normal file
6
examples/go-echo/hero.fbs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace hero;
|
||||||
|
|
||||||
|
table Warrior {
|
||||||
|
name: string;
|
||||||
|
hp: uint32;
|
||||||
|
}
|
||||||
93
examples/go-echo/hero/Warrior.go
Normal file
93
examples/go-echo/hero/Warrior.go
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
|
||||||
|
|
||||||
|
package hero
|
||||||
|
|
||||||
|
import (
|
||||||
|
flatbuffers "github.com/google/flatbuffers/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WarriorT struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Hp uint32 `json:"hp"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *WarriorT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||||
|
if t == nil { return 0 }
|
||||||
|
nameOffset := builder.CreateString(t.Name)
|
||||||
|
WarriorStart(builder)
|
||||||
|
WarriorAddName(builder, nameOffset)
|
||||||
|
WarriorAddHp(builder, t.Hp)
|
||||||
|
return WarriorEnd(builder)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rcv *Warrior) UnPackTo(t *WarriorT) {
|
||||||
|
t.Name = string(rcv.Name())
|
||||||
|
t.Hp = rcv.Hp()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rcv *Warrior) UnPack() *WarriorT {
|
||||||
|
if rcv == nil { return nil }
|
||||||
|
t := &WarriorT{}
|
||||||
|
rcv.UnPackTo(t)
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
type Warrior struct {
|
||||||
|
_tab flatbuffers.Table
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetRootAsWarrior(buf []byte, offset flatbuffers.UOffsetT) *Warrior {
|
||||||
|
n := flatbuffers.GetUOffsetT(buf[offset:])
|
||||||
|
x := &Warrior{}
|
||||||
|
x.Init(buf, n+offset)
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetSizePrefixedRootAsWarrior(buf []byte, offset flatbuffers.UOffsetT) *Warrior {
|
||||||
|
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
|
||||||
|
x := &Warrior{}
|
||||||
|
x.Init(buf, n+offset+flatbuffers.SizeUint32)
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rcv *Warrior) Init(buf []byte, i flatbuffers.UOffsetT) {
|
||||||
|
rcv._tab.Bytes = buf
|
||||||
|
rcv._tab.Pos = i
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rcv *Warrior) Table() flatbuffers.Table {
|
||||||
|
return rcv._tab
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rcv *Warrior) Name() []byte {
|
||||||
|
o := flatbuffers.UOffsetT(rcv._tab.Offset(4))
|
||||||
|
if o != 0 {
|
||||||
|
return rcv._tab.ByteVector(o + rcv._tab.Pos)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rcv *Warrior) Hp() uint32 {
|
||||||
|
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
|
||||||
|
if o != 0 {
|
||||||
|
return rcv._tab.GetUint32(o + rcv._tab.Pos)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rcv *Warrior) MutateHp(n uint32) bool {
|
||||||
|
return rcv._tab.MutateUint32Slot(6, n)
|
||||||
|
}
|
||||||
|
|
||||||
|
func WarriorStart(builder *flatbuffers.Builder) {
|
||||||
|
builder.StartObject(2)
|
||||||
|
}
|
||||||
|
func WarriorAddName(builder *flatbuffers.Builder, name flatbuffers.UOffsetT) {
|
||||||
|
builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(name), 0)
|
||||||
|
}
|
||||||
|
func WarriorAddHp(builder *flatbuffers.Builder, hp uint32) {
|
||||||
|
builder.PrependUint32Slot(1, hp, 0)
|
||||||
|
}
|
||||||
|
func WarriorEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||||
|
return builder.EndObject()
|
||||||
|
}
|
||||||
11
examples/go-echo/net.fbs
Normal file
11
examples/go-echo/net.fbs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
include "hero.fbs";
|
||||||
|
|
||||||
|
namespace net;
|
||||||
|
|
||||||
|
table Request {
|
||||||
|
player: hero.Warrior;
|
||||||
|
}
|
||||||
|
|
||||||
|
table Response {
|
||||||
|
player: hero.Warrior;
|
||||||
|
}
|
||||||
82
examples/go-echo/net/Request.go
Normal file
82
examples/go-echo/net/Request.go
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
|
||||||
|
|
||||||
|
package net
|
||||||
|
|
||||||
|
import (
|
||||||
|
flatbuffers "github.com/google/flatbuffers/go"
|
||||||
|
|
||||||
|
hero "echo/hero"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RequestT struct {
|
||||||
|
Player *hero.WarriorT `json:"player"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *RequestT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||||
|
if t == nil { return 0 }
|
||||||
|
playerOffset := t.Player.Pack(builder)
|
||||||
|
RequestStart(builder)
|
||||||
|
RequestAddPlayer(builder, playerOffset)
|
||||||
|
return RequestEnd(builder)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rcv *Request) UnPackTo(t *RequestT) {
|
||||||
|
t.Player = rcv.Player(nil).UnPack()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rcv *Request) UnPack() *RequestT {
|
||||||
|
if rcv == nil { return nil }
|
||||||
|
t := &RequestT{}
|
||||||
|
rcv.UnPackTo(t)
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
type Request struct {
|
||||||
|
_tab flatbuffers.Table
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetRootAsRequest(buf []byte, offset flatbuffers.UOffsetT) *Request {
|
||||||
|
n := flatbuffers.GetUOffsetT(buf[offset:])
|
||||||
|
x := &Request{}
|
||||||
|
x.Init(buf, n+offset)
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetSizePrefixedRootAsRequest(buf []byte, offset flatbuffers.UOffsetT) *Request {
|
||||||
|
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
|
||||||
|
x := &Request{}
|
||||||
|
x.Init(buf, n+offset+flatbuffers.SizeUint32)
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rcv *Request) Init(buf []byte, i flatbuffers.UOffsetT) {
|
||||||
|
rcv._tab.Bytes = buf
|
||||||
|
rcv._tab.Pos = i
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rcv *Request) Table() flatbuffers.Table {
|
||||||
|
return rcv._tab
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rcv *Request) Player(obj *hero.Warrior) *hero.Warrior {
|
||||||
|
o := flatbuffers.UOffsetT(rcv._tab.Offset(4))
|
||||||
|
if o != 0 {
|
||||||
|
x := rcv._tab.Indirect(o + rcv._tab.Pos)
|
||||||
|
if obj == nil {
|
||||||
|
obj = new(hero.Warrior)
|
||||||
|
}
|
||||||
|
obj.Init(rcv._tab.Bytes, x)
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func RequestStart(builder *flatbuffers.Builder) {
|
||||||
|
builder.StartObject(1)
|
||||||
|
}
|
||||||
|
func RequestAddPlayer(builder *flatbuffers.Builder, player flatbuffers.UOffsetT) {
|
||||||
|
builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(player), 0)
|
||||||
|
}
|
||||||
|
func RequestEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||||
|
return builder.EndObject()
|
||||||
|
}
|
||||||
82
examples/go-echo/net/Response.go
Normal file
82
examples/go-echo/net/Response.go
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
|
||||||
|
|
||||||
|
package net
|
||||||
|
|
||||||
|
import (
|
||||||
|
flatbuffers "github.com/google/flatbuffers/go"
|
||||||
|
|
||||||
|
hero "echo/hero"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ResponseT struct {
|
||||||
|
Player *hero.WarriorT `json:"player"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *ResponseT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||||
|
if t == nil { return 0 }
|
||||||
|
playerOffset := t.Player.Pack(builder)
|
||||||
|
ResponseStart(builder)
|
||||||
|
ResponseAddPlayer(builder, playerOffset)
|
||||||
|
return ResponseEnd(builder)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rcv *Response) UnPackTo(t *ResponseT) {
|
||||||
|
t.Player = rcv.Player(nil).UnPack()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rcv *Response) UnPack() *ResponseT {
|
||||||
|
if rcv == nil { return nil }
|
||||||
|
t := &ResponseT{}
|
||||||
|
rcv.UnPackTo(t)
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
type Response struct {
|
||||||
|
_tab flatbuffers.Table
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetRootAsResponse(buf []byte, offset flatbuffers.UOffsetT) *Response {
|
||||||
|
n := flatbuffers.GetUOffsetT(buf[offset:])
|
||||||
|
x := &Response{}
|
||||||
|
x.Init(buf, n+offset)
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetSizePrefixedRootAsResponse(buf []byte, offset flatbuffers.UOffsetT) *Response {
|
||||||
|
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
|
||||||
|
x := &Response{}
|
||||||
|
x.Init(buf, n+offset+flatbuffers.SizeUint32)
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rcv *Response) Init(buf []byte, i flatbuffers.UOffsetT) {
|
||||||
|
rcv._tab.Bytes = buf
|
||||||
|
rcv._tab.Pos = i
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rcv *Response) Table() flatbuffers.Table {
|
||||||
|
return rcv._tab
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rcv *Response) Player(obj *hero.Warrior) *hero.Warrior {
|
||||||
|
o := flatbuffers.UOffsetT(rcv._tab.Offset(4))
|
||||||
|
if o != 0 {
|
||||||
|
x := rcv._tab.Indirect(o + rcv._tab.Pos)
|
||||||
|
if obj == nil {
|
||||||
|
obj = new(hero.Warrior)
|
||||||
|
}
|
||||||
|
obj.Init(rcv._tab.Bytes, x)
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ResponseStart(builder *flatbuffers.Builder) {
|
||||||
|
builder.StartObject(1)
|
||||||
|
}
|
||||||
|
func ResponseAddPlayer(builder *flatbuffers.Builder, player flatbuffers.UOffsetT) {
|
||||||
|
builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(player), 0)
|
||||||
|
}
|
||||||
|
func ResponseEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||||
|
return builder.EndObject()
|
||||||
|
}
|
||||||
29
examples/go-echo/server/server.go
Normal file
29
examples/go-echo/server/server.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"echo/net"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func echo(w http.ResponseWriter, r *http.Request) {
|
||||||
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Unable to read request body: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
req := net.GetRootAsRequest(body, 0)
|
||||||
|
player := req.Player(nil)
|
||||||
|
|
||||||
|
fmt.Printf("Got request (name: %v, hp: %v)\n", string(player.Name()), player.Hp())
|
||||||
|
w.Write(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
http.HandleFunc("/echo", echo)
|
||||||
|
|
||||||
|
fmt.Println("Listening on port :8080")
|
||||||
|
http.ListenAndServe(":8080", nil)
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package flatbuffers
|
package flatbuffers
|
||||||
|
|
||||||
|
import "sort"
|
||||||
|
|
||||||
// Builder is a state machine for creating FlatBuffer objects.
|
// Builder is a state machine for creating FlatBuffer objects.
|
||||||
// Use a Builder to construct object(s) starting from leaf nodes.
|
// Use a Builder to construct object(s) starting from leaf nodes.
|
||||||
//
|
//
|
||||||
@@ -315,6 +317,25 @@ func (b *Builder) EndVector(vectorNumElems int) UOffsetT {
|
|||||||
return b.Offset()
|
return b.Offset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateVectorOfTables serializes slice of table offsets into a vector.
|
||||||
|
func (b *Builder) CreateVectorOfTables(offsets []UOffsetT) UOffsetT {
|
||||||
|
b.assertNotNested()
|
||||||
|
b.StartVector(4, len(offsets), 4)
|
||||||
|
for i := len(offsets) - 1; i >= 0; i-- {
|
||||||
|
b.PrependUOffsetT(offsets[i])
|
||||||
|
}
|
||||||
|
return b.EndVector(len(offsets))
|
||||||
|
}
|
||||||
|
|
||||||
|
type KeyCompare func(o1, o2 UOffsetT, buf []byte) bool
|
||||||
|
|
||||||
|
func (b *Builder) CreateVectorOfSortedTables(offsets []UOffsetT, keyCompare KeyCompare) UOffsetT {
|
||||||
|
sort.Slice(offsets, func(i, j int) bool {
|
||||||
|
return keyCompare(offsets[i], offsets[j], b.Bytes)
|
||||||
|
})
|
||||||
|
return b.CreateVectorOfTables(offsets)
|
||||||
|
}
|
||||||
|
|
||||||
// CreateSharedString Checks if the string is already written
|
// CreateSharedString Checks if the string is already written
|
||||||
// to the buffer before calling CreateString
|
// to the buffer before calling CreateString
|
||||||
func (b *Builder) CreateSharedString(s string) UOffsetT {
|
func (b *Builder) CreateSharedString(s string) UOffsetT {
|
||||||
|
|||||||
@@ -23,3 +23,8 @@ func GetSizePrefixedRootAs(buf []byte, offset UOffsetT, fb FlatBuffer) {
|
|||||||
func GetSizePrefix(buf []byte, offset UOffsetT) uint32 {
|
func GetSizePrefix(buf []byte, offset UOffsetT) uint32 {
|
||||||
return GetUint32(buf[offset:])
|
return GetUint32(buf[offset:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetIndirectOffset retrives the relative offset in the provided buffer stored at `offset`.
|
||||||
|
func GetIndirectOffset(buf []byte, offset UOffsetT) UOffsetT {
|
||||||
|
return offset + GetUOffsetT(buf[offset:])
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,12 +6,10 @@ import FlatBuffers
|
|||||||
|
|
||||||
public struct models_HelloReply: FlatBufferObject, Verifiable {
|
public struct models_HelloReply: FlatBufferObject, Verifiable {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_22_10_26() }
|
static func validateVersion() { FlatBuffersVersion_23_1_20() }
|
||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
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 }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
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 {
|
public struct models_HelloRequest: FlatBufferObject, Verifiable {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_22_10_26() }
|
static func validateVersion() { FlatBuffersVersion_23_1_20() }
|
||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
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 }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
#ifndef FLATBUFFERS_ARRAY_H_
|
#ifndef FLATBUFFERS_ARRAY_H_
|
||||||
#define FLATBUFFERS_ARRAY_H_
|
#define FLATBUFFERS_ARRAY_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "flatbuffers/base.h"
|
#include "flatbuffers/base.h"
|
||||||
#include "flatbuffers/stl_emulation.h"
|
#include "flatbuffers/stl_emulation.h"
|
||||||
#include "flatbuffers/vector.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);
|
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
|
} // namespace flatbuffers
|
||||||
|
|
||||||
#endif // FLATBUFFERS_ARRAY_H_
|
#endif // FLATBUFFERS_ARRAY_H_
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#if defined(ARDUINO) && !defined(ARDUINOSTL_M_H)
|
#if defined(ARDUINO) && !defined(ARDUINOSTL_M_H) && defined(__AVR__)
|
||||||
#include <utility.h>
|
#include <utility.h>
|
||||||
#else
|
#else
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -138,9 +138,9 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
|
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
|
||||||
|
|
||||||
#define FLATBUFFERS_VERSION_MAJOR 22
|
#define FLATBUFFERS_VERSION_MAJOR 23
|
||||||
#define FLATBUFFERS_VERSION_MINOR 10
|
#define FLATBUFFERS_VERSION_MINOR 1
|
||||||
#define FLATBUFFERS_VERSION_REVISION 26
|
#define FLATBUFFERS_VERSION_REVISION 20
|
||||||
#define FLATBUFFERS_STRING_EXPAND(X) #X
|
#define FLATBUFFERS_STRING_EXPAND(X) #X
|
||||||
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
|
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
|
||||||
namespace flatbuffers {
|
namespace flatbuffers {
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
#ifndef FLATBUFFERS_BUFFER_H_
|
#ifndef FLATBUFFERS_BUFFER_H_
|
||||||
#define FLATBUFFERS_BUFFER_H_
|
#define FLATBUFFERS_BUFFER_H_
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "flatbuffers/base.h"
|
#include "flatbuffers/base.h"
|
||||||
|
|
||||||
namespace flatbuffers {
|
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),
|
cur_(cur),
|
||||||
size_(sz) {}
|
size_(sz) {}
|
||||||
|
|
||||||
DetachedBuffer(DetachedBuffer &&other)
|
DetachedBuffer(DetachedBuffer &&other) noexcept
|
||||||
: allocator_(other.allocator_),
|
: allocator_(other.allocator_),
|
||||||
own_allocator_(other.own_allocator_),
|
own_allocator_(other.own_allocator_),
|
||||||
buf_(other.buf_),
|
buf_(other.buf_),
|
||||||
@@ -55,7 +55,7 @@ class DetachedBuffer {
|
|||||||
other.reset();
|
other.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
DetachedBuffer &operator=(DetachedBuffer &&other) {
|
DetachedBuffer &operator=(DetachedBuffer &&other) noexcept {
|
||||||
if (this == &other) return *this;
|
if (this == &other) return *this;
|
||||||
|
|
||||||
destroy();
|
destroy();
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#ifndef FLATBUFFERS_FLATBUFFER_BUILDER_H_
|
#ifndef FLATBUFFERS_FLATBUFFER_BUILDER_H_
|
||||||
#define FLATBUFFERS_FLATBUFFER_BUILDER_H_
|
#define FLATBUFFERS_FLATBUFFER_BUILDER_H_
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
|
|
||||||
@@ -97,7 +98,7 @@ class FlatBufferBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Move constructor for FlatBufferBuilder.
|
/// @brief Move constructor for FlatBufferBuilder.
|
||||||
FlatBufferBuilder(FlatBufferBuilder &&other)
|
FlatBufferBuilder(FlatBufferBuilder &&other) noexcept
|
||||||
: buf_(1024, nullptr, false, AlignOf<largest_scalar_t>()),
|
: buf_(1024, nullptr, false, AlignOf<largest_scalar_t>()),
|
||||||
num_field_loc(0),
|
num_field_loc(0),
|
||||||
max_voffset_(0),
|
max_voffset_(0),
|
||||||
@@ -115,7 +116,7 @@ class FlatBufferBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Move assignment operator for FlatBufferBuilder.
|
/// @brief Move assignment operator for FlatBufferBuilder.
|
||||||
FlatBufferBuilder &operator=(FlatBufferBuilder &&other) {
|
FlatBufferBuilder &operator=(FlatBufferBuilder &&other) noexcept {
|
||||||
// Move construct a temporary and swap idiom
|
// Move construct a temporary and swap idiom
|
||||||
FlatBufferBuilder temp(std::move(other));
|
FlatBufferBuilder temp(std::move(other));
|
||||||
Swap(temp);
|
Swap(temp);
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
#ifndef FLATBUFFERS_H_
|
#ifndef FLATBUFFERS_H_
|
||||||
#define FLATBUFFERS_H_
|
#define FLATBUFFERS_H_
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
// TODO: These includes are for mitigating the pains of users editing their
|
// TODO: These includes are for mitigating the pains of users editing their
|
||||||
// source because they relied on flatbuffers.h to include everything for them.
|
// source because they relied on flatbuffers.h to include everything for them.
|
||||||
#include "flatbuffers/array.h"
|
#include "flatbuffers/array.h"
|
||||||
|
|||||||
@@ -19,18 +19,51 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <list>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "flatbuffers/bfbs_generator.h"
|
#include "flatbuffers/bfbs_generator.h"
|
||||||
|
#include "flatbuffers/code_generator.h"
|
||||||
#include "flatbuffers/flatbuffers.h"
|
#include "flatbuffers/flatbuffers.h"
|
||||||
#include "flatbuffers/idl.h"
|
#include "flatbuffers/idl.h"
|
||||||
#include "flatbuffers/util.h"
|
#include "flatbuffers/util.h"
|
||||||
|
|
||||||
namespace flatbuffers {
|
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 LogCompilerWarn(const std::string &warn);
|
||||||
extern void LogCompilerError(const std::string &err);
|
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 {
|
struct FlatCOption {
|
||||||
std::string short_opt;
|
std::string short_opt;
|
||||||
std::string long_opt;
|
std::string long_opt;
|
||||||
@@ -85,15 +118,21 @@ class FlatCompiler {
|
|||||||
|
|
||||||
explicit FlatCompiler(const InitParams ¶ms) : params_(params) {}
|
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;
|
int Compile(const FlatCOptions &options);
|
||||||
std::string GetUsageString(const char *program_name) const;
|
|
||||||
|
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:
|
private:
|
||||||
void ParseFile(flatbuffers::Parser &parser, const std::string &filename,
|
void ParseFile(flatbuffers::Parser &parser, const std::string &filename,
|
||||||
const std::string &contents,
|
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,
|
void LoadBinarySchema(Parser &parser, const std::string &filename,
|
||||||
const std::string &contents);
|
const std::string &contents);
|
||||||
@@ -105,9 +144,18 @@ class FlatCompiler {
|
|||||||
|
|
||||||
void AnnotateBinaries(const uint8_t *binary_schema,
|
void AnnotateBinaries(const uint8_t *binary_schema,
|
||||||
uint64_t binary_schema_size,
|
uint64_t binary_schema_size,
|
||||||
const std::string & schema_filename,
|
const std::string &schema_filename,
|
||||||
const std::vector<std::string> &binary_files);
|
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_;
|
InitParams params_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#ifndef FLATBUFFERS_FLEXBUFFERS_H_
|
#ifndef FLATBUFFERS_FLEXBUFFERS_H_
|
||||||
#define FLATBUFFERS_FLEXBUFFERS_H_
|
#define FLATBUFFERS_FLEXBUFFERS_H_
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <map>
|
#include <map>
|
||||||
// Used to select STL variant.
|
// Used to select STL variant.
|
||||||
#include "flatbuffers/base.h"
|
#include "flatbuffers/base.h"
|
||||||
@@ -382,10 +383,10 @@ class Reference {
|
|||||||
type_(type) {}
|
type_(type) {}
|
||||||
|
|
||||||
Reference(const uint8_t *data, uint8_t parent_width, uint8_t packed_type)
|
Reference(const uint8_t *data, uint8_t parent_width, uint8_t packed_type)
|
||||||
: data_(data), parent_width_(parent_width) {
|
: data_(data),
|
||||||
byte_width_ = 1U << static_cast<BitWidth>(packed_type & 3);
|
parent_width_(parent_width),
|
||||||
type_ = static_cast<Type>(packed_type >> 2);
|
byte_width_(static_cast<uint8_t>(1 << (packed_type & 3))),
|
||||||
}
|
type_(static_cast<Type>(packed_type >> 2)) {}
|
||||||
|
|
||||||
Type GetType() const { return type_; }
|
Type GetType() const { return type_; }
|
||||||
|
|
||||||
@@ -1844,7 +1845,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
|||||||
uint8_t len = 0;
|
uint8_t len = 0;
|
||||||
auto vtype = ToFixedTypedVectorElementType(r.type_, &len);
|
auto vtype = ToFixedTypedVectorElementType(r.type_, &len);
|
||||||
if (!VerifyType(vtype)) return false;
|
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;
|
default: return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#ifndef FLATBUFFERS_IDL_H_
|
#ifndef FLATBUFFERS_IDL_H_
|
||||||
#define FLATBUFFERS_IDL_H_
|
#define FLATBUFFERS_IDL_H_
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -296,7 +297,8 @@ struct FieldDef : public Definition {
|
|||||||
flexbuffer(false),
|
flexbuffer(false),
|
||||||
presence(kDefault),
|
presence(kDefault),
|
||||||
nested_flatbuffer(nullptr),
|
nested_flatbuffer(nullptr),
|
||||||
padding(0) {}
|
padding(0),
|
||||||
|
sibling_union_field(nullptr) {}
|
||||||
|
|
||||||
Offset<reflection::Field> Serialize(FlatBufferBuilder *builder, uint16_t id,
|
Offset<reflection::Field> Serialize(FlatBufferBuilder *builder, uint16_t id,
|
||||||
const Parser &parser) const;
|
const Parser &parser) const;
|
||||||
@@ -341,6 +343,12 @@ struct FieldDef : public Definition {
|
|||||||
|
|
||||||
StructDef *nested_flatbuffer; // This field contains nested FlatBuffer data.
|
StructDef *nested_flatbuffer; // This field contains nested FlatBuffer data.
|
||||||
size_t padding; // Bytes to always pad after this field.
|
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 {
|
struct StructDef : public Definition {
|
||||||
@@ -472,6 +480,10 @@ inline bool IsStruct(const Type &type) {
|
|||||||
return type.base_type == BASE_TYPE_STRUCT && type.struct_def->fixed;
|
return type.base_type == BASE_TYPE_STRUCT && type.struct_def->fixed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool IsIncompleteStruct(const Type &type) {
|
||||||
|
return type.base_type == BASE_TYPE_STRUCT && type.struct_def->predecl;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool IsTable(const Type &type) {
|
inline bool IsTable(const Type &type) {
|
||||||
return type.base_type == BASE_TYPE_STRUCT && !type.struct_def->fixed;
|
return type.base_type == BASE_TYPE_STRUCT && !type.struct_def->fixed;
|
||||||
}
|
}
|
||||||
@@ -488,11 +500,11 @@ inline bool IsVector(const Type &type) {
|
|||||||
return type.base_type == BASE_TYPE_VECTOR;
|
return type.base_type == BASE_TYPE_VECTOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool IsVectorOfStruct(const Type& type) {
|
inline bool IsVectorOfStruct(const Type &type) {
|
||||||
return IsVector(type) && IsStruct(type.VectorType());
|
return IsVector(type) && IsStruct(type.VectorType());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool IsVectorOfTable(const Type& type) {
|
inline bool IsVectorOfTable(const Type &type) {
|
||||||
return IsVector(type) && IsTable(type.VectorType());
|
return IsVector(type) && IsTable(type.VectorType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,8 +548,11 @@ inline bool operator!=(const EnumVal &lhs, const EnumVal &rhs) {
|
|||||||
inline bool EqualByName(const Type &a, const Type &b) {
|
inline bool EqualByName(const Type &a, const Type &b) {
|
||||||
return a.base_type == b.base_type && a.element == b.element &&
|
return a.base_type == b.base_type && a.element == b.element &&
|
||||||
(a.struct_def == b.struct_def ||
|
(a.struct_def == b.struct_def ||
|
||||||
a.struct_def->name == b.struct_def->name) &&
|
(a.struct_def != nullptr && b.struct_def != nullptr &&
|
||||||
(a.enum_def == b.enum_def || a.enum_def->name == b.enum_def->name);
|
a.struct_def->name == b.struct_def->name)) &&
|
||||||
|
(a.enum_def == b.enum_def ||
|
||||||
|
(a.enum_def != nullptr && b.enum_def != nullptr &&
|
||||||
|
a.enum_def->name == b.enum_def->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RPCCall : public Definition {
|
struct RPCCall : public Definition {
|
||||||
@@ -586,9 +601,11 @@ struct IDLOptions {
|
|||||||
bool strict_json;
|
bool strict_json;
|
||||||
bool output_default_scalars_in_json;
|
bool output_default_scalars_in_json;
|
||||||
int indent_step;
|
int indent_step;
|
||||||
|
bool cpp_minify_enums;
|
||||||
bool output_enum_identifiers;
|
bool output_enum_identifiers;
|
||||||
bool prefixed_enums;
|
bool prefixed_enums;
|
||||||
bool scoped_enums;
|
bool scoped_enums;
|
||||||
|
bool emit_min_max_enum_values;
|
||||||
bool swift_implementation_only;
|
bool swift_implementation_only;
|
||||||
bool include_dependence_headers;
|
bool include_dependence_headers;
|
||||||
bool mutable_buffer;
|
bool mutable_buffer;
|
||||||
@@ -621,6 +638,7 @@ struct IDLOptions {
|
|||||||
bool binary_schema_gen_embed;
|
bool binary_schema_gen_embed;
|
||||||
std::string go_import;
|
std::string go_import;
|
||||||
std::string go_namespace;
|
std::string go_namespace;
|
||||||
|
std::string go_module_name;
|
||||||
bool protobuf_ascii_alike;
|
bool protobuf_ascii_alike;
|
||||||
bool size_prefixed;
|
bool size_prefixed;
|
||||||
std::string root_type;
|
std::string root_type;
|
||||||
@@ -641,7 +659,9 @@ struct IDLOptions {
|
|||||||
bool json_nested_flexbuffers;
|
bool json_nested_flexbuffers;
|
||||||
bool json_nested_legacy_flatbuffers;
|
bool json_nested_legacy_flatbuffers;
|
||||||
bool ts_flat_file;
|
bool ts_flat_file;
|
||||||
|
bool ts_no_import_ext;
|
||||||
bool no_leak_private_annotations;
|
bool no_leak_private_annotations;
|
||||||
|
bool require_json_eof;
|
||||||
|
|
||||||
// Possible options for the more general generator below.
|
// Possible options for the more general generator below.
|
||||||
enum Language {
|
enum Language {
|
||||||
@@ -696,9 +716,11 @@ struct IDLOptions {
|
|||||||
strict_json(false),
|
strict_json(false),
|
||||||
output_default_scalars_in_json(false),
|
output_default_scalars_in_json(false),
|
||||||
indent_step(2),
|
indent_step(2),
|
||||||
|
cpp_minify_enums(false),
|
||||||
output_enum_identifiers(true),
|
output_enum_identifiers(true),
|
||||||
prefixed_enums(true),
|
prefixed_enums(true),
|
||||||
scoped_enums(false),
|
scoped_enums(false),
|
||||||
|
emit_min_max_enum_values(true),
|
||||||
swift_implementation_only(false),
|
swift_implementation_only(false),
|
||||||
include_dependence_headers(true),
|
include_dependence_headers(true),
|
||||||
mutable_buffer(false),
|
mutable_buffer(false),
|
||||||
@@ -742,7 +764,9 @@ struct IDLOptions {
|
|||||||
json_nested_flexbuffers(true),
|
json_nested_flexbuffers(true),
|
||||||
json_nested_legacy_flatbuffers(false),
|
json_nested_legacy_flatbuffers(false),
|
||||||
ts_flat_file(false),
|
ts_flat_file(false),
|
||||||
|
ts_no_import_ext(false),
|
||||||
no_leak_private_annotations(false),
|
no_leak_private_annotations(false),
|
||||||
|
require_json_eof(true),
|
||||||
mini_reflect(IDLOptions::kNone),
|
mini_reflect(IDLOptions::kNone),
|
||||||
require_explicit_ids(false),
|
require_explicit_ids(false),
|
||||||
rust_serialize(false),
|
rust_serialize(false),
|
||||||
@@ -755,7 +779,8 @@ struct IDLOptions {
|
|||||||
// This encapsulates where the parser is in the current source file.
|
// This encapsulates where the parser is in the current source file.
|
||||||
struct ParserState {
|
struct ParserState {
|
||||||
ParserState()
|
ParserState()
|
||||||
: cursor_(nullptr),
|
: prev_cursor_(nullptr),
|
||||||
|
cursor_(nullptr),
|
||||||
line_start_(nullptr),
|
line_start_(nullptr),
|
||||||
line_(0),
|
line_(0),
|
||||||
token_(-1),
|
token_(-1),
|
||||||
@@ -763,6 +788,7 @@ struct ParserState {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ResetState(const char *source) {
|
void ResetState(const char *source) {
|
||||||
|
prev_cursor_ = source;
|
||||||
cursor_ = source;
|
cursor_ = source;
|
||||||
line_ = 0;
|
line_ = 0;
|
||||||
MarkNewLine();
|
MarkNewLine();
|
||||||
@@ -778,6 +804,7 @@ struct ParserState {
|
|||||||
return static_cast<int64_t>(cursor_ - line_start_);
|
return static_cast<int64_t>(cursor_ - line_start_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *prev_cursor_;
|
||||||
const char *cursor_;
|
const char *cursor_;
|
||||||
const char *line_start_;
|
const char *line_start_;
|
||||||
int line_; // the current line being parsed
|
int line_; // the current line being parsed
|
||||||
@@ -883,6 +910,13 @@ class Parser : public ParserState {
|
|||||||
known_attributes_["private"] = true;
|
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() {
|
~Parser() {
|
||||||
for (auto it = namespaces_.begin(); it != namespaces_.end(); ++it) {
|
for (auto it = namespaces_.begin(); it != namespaces_.end(); ++it) {
|
||||||
delete *it;
|
delete *it;
|
||||||
@@ -905,6 +939,9 @@ class Parser : public ParserState {
|
|||||||
|
|
||||||
bool ParseJson(const char *json, const char *json_filename = nullptr);
|
bool ParseJson(const char *json, const char *json_filename = nullptr);
|
||||||
|
|
||||||
|
// Returns the number of characters were consumed when parsing a JSON string.
|
||||||
|
std::ptrdiff_t BytesConsumed() const;
|
||||||
|
|
||||||
// Set the root type. May override the one set in the schema.
|
// Set the root type. May override the one set in the schema.
|
||||||
bool SetRootType(const char *name);
|
bool SetRootType(const char *name);
|
||||||
|
|
||||||
@@ -1025,6 +1062,7 @@ class Parser : public ParserState {
|
|||||||
FLATBUFFERS_CHECKED_ERROR ParseService(const char *filename);
|
FLATBUFFERS_CHECKED_ERROR ParseService(const char *filename);
|
||||||
FLATBUFFERS_CHECKED_ERROR ParseProtoFields(StructDef *struct_def,
|
FLATBUFFERS_CHECKED_ERROR ParseProtoFields(StructDef *struct_def,
|
||||||
bool isextend, bool inside_oneof);
|
bool isextend, bool inside_oneof);
|
||||||
|
FLATBUFFERS_CHECKED_ERROR ParseProtoMapField(StructDef *struct_def);
|
||||||
FLATBUFFERS_CHECKED_ERROR ParseProtoOption();
|
FLATBUFFERS_CHECKED_ERROR ParseProtoOption();
|
||||||
FLATBUFFERS_CHECKED_ERROR ParseProtoKey();
|
FLATBUFFERS_CHECKED_ERROR ParseProtoKey();
|
||||||
FLATBUFFERS_CHECKED_ERROR ParseProtoDecl();
|
FLATBUFFERS_CHECKED_ERROR ParseProtoDecl();
|
||||||
|
|||||||
@@ -407,8 +407,9 @@ struct ToStringVisitor : public IterationVisitor {
|
|||||||
inline std::string FlatBufferToString(const uint8_t *buffer,
|
inline std::string FlatBufferToString(const uint8_t *buffer,
|
||||||
const TypeTable *type_table,
|
const TypeTable *type_table,
|
||||||
bool multi_line = false,
|
bool multi_line = false,
|
||||||
bool vector_delimited = true) {
|
bool vector_delimited = true,
|
||||||
ToStringVisitor tostring_visitor(multi_line ? "\n" : " ", false, "",
|
const std::string& indent = "") {
|
||||||
|
ToStringVisitor tostring_visitor(multi_line ? "\n" : " ", false, indent,
|
||||||
vector_delimited);
|
vector_delimited);
|
||||||
IterateFlatBuffer(buffer, type_table, &tostring_visitor);
|
IterateFlatBuffer(buffer, type_table, &tostring_visitor);
|
||||||
return tostring_visitor.s;
|
return tostring_visitor.s;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -31,6 +31,8 @@
|
|||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
#endif // FLATBUFFERS_PREFER_PRINTF
|
#endif // FLATBUFFERS_PREFER_PRINTF
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace flatbuffers {
|
namespace flatbuffers {
|
||||||
@@ -312,6 +314,7 @@ inline bool StringToFloatImpl(T *val, const char *const str) {
|
|||||||
strtoval_impl(val, str, const_cast<char **>(&end));
|
strtoval_impl(val, str, const_cast<char **>(&end));
|
||||||
auto done = (end != str) && (*end == '\0');
|
auto done = (end != str) && (*end == '\0');
|
||||||
if (!done) *val = 0; // erase partial result
|
if (!done) *val = 0; // erase partial result
|
||||||
|
if (done && std::isnan(*val)) { *val = std::numeric_limits<T>::quiet_NaN(); }
|
||||||
return done;
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,6 +395,18 @@ inline uint64_t StringToUInt(const char *s, int base = 10) {
|
|||||||
return StringToIntegerImpl(&val, s, base) ? val : 0;
|
return StringToIntegerImpl(&val, s, base) ? val : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool StringIsFlatbufferNan(const std::string &s) {
|
||||||
|
return s == "nan" || s == "+nan" || s == "-nan";
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool StringIsFlatbufferPositiveInfinity(const std::string &s) {
|
||||||
|
return s == "inf" || s == "+inf" || s == "infinity" || s == "+infinity";
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool StringIsFlatbufferNegativeInfinity(const std::string &s) {
|
||||||
|
return s == "-inf" || s == "-infinity";
|
||||||
|
}
|
||||||
|
|
||||||
typedef bool (*LoadFileFunction)(const char *filename, bool binary,
|
typedef bool (*LoadFileFunction)(const char *filename, bool binary,
|
||||||
std::string *dest);
|
std::string *dest);
|
||||||
typedef bool (*FileExistsFunction)(const char *filename);
|
typedef bool (*FileExistsFunction)(const char *filename);
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
#ifndef FLATBUFFERS_VECTOR_DOWNWARD_H_
|
#ifndef FLATBUFFERS_VECTOR_DOWNWARD_H_
|
||||||
#define FLATBUFFERS_VECTOR_DOWNWARD_H_
|
#define FLATBUFFERS_VECTOR_DOWNWARD_H_
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "flatbuffers/base.h"
|
#include "flatbuffers/base.h"
|
||||||
#include "flatbuffers/default_allocator.h"
|
#include "flatbuffers/default_allocator.h"
|
||||||
#include "flatbuffers/detached_buffer.h"
|
#include "flatbuffers/detached_buffer.h"
|
||||||
@@ -43,7 +45,7 @@ class vector_downward {
|
|||||||
cur_(nullptr),
|
cur_(nullptr),
|
||||||
scratch_(nullptr) {}
|
scratch_(nullptr) {}
|
||||||
|
|
||||||
vector_downward(vector_downward &&other)
|
vector_downward(vector_downward &&other) noexcept
|
||||||
// clang-format on
|
// clang-format on
|
||||||
: allocator_(other.allocator_),
|
: allocator_(other.allocator_),
|
||||||
own_allocator_(other.own_allocator_),
|
own_allocator_(other.own_allocator_),
|
||||||
@@ -64,7 +66,7 @@ class vector_downward {
|
|||||||
other.scratch_ = nullptr;
|
other.scratch_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector_downward &operator=(vector_downward &&other) {
|
vector_downward &operator=(vector_downward &&other) noexcept {
|
||||||
// Move construct a temporary and swap idiom
|
// Move construct a temporary and swap idiom
|
||||||
vector_downward temp(std::move(other));
|
vector_downward temp(std::move(other));
|
||||||
swap(temp);
|
swap(temp);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.google.flatbuffers</groupId>
|
<groupId>com.google.flatbuffers</groupId>
|
||||||
<artifactId>flatbuffers-java</artifactId>
|
<artifactId>flatbuffers-java</artifactId>
|
||||||
<version>22.10.26</version>
|
<version>23.1.4</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>FlatBuffers Java API</name>
|
<name>FlatBuffers Java API</name>
|
||||||
<description>
|
<description>
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class Constants {
|
|||||||
Changes to the Java implementation need to be sure to change
|
Changes to the Java implementation need to be sure to change
|
||||||
the version here and in the code generator on every possible
|
the version here and in the code generator on every possible
|
||||||
incompatible change */
|
incompatible change */
|
||||||
public static void FLATBUFFERS_22_10_26() {}
|
public static void FLATBUFFERS_23_1_20() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @endcond
|
/// @endcond
|
||||||
|
|||||||
@@ -32,6 +32,6 @@ namespace Google.FlatBuffers
|
|||||||
Changes to the C# implementation need to be sure to change
|
Changes to the C# implementation need to be sure to change
|
||||||
the version here and in the code generator on every possible
|
the version here and in the code generator on every possible
|
||||||
incompatible change */
|
incompatible change */
|
||||||
public static void FLATBUFFERS_22_10_26() {}
|
public static void FLATBUFFERS_23_1_20() {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netstandard2.1;netstandard2.0;net46</TargetFrameworks>
|
<TargetFrameworks>netstandard2.1;netstandard2.0;net46</TargetFrameworks>
|
||||||
<Description>A cross-platform memory efficient serialization library</Description>
|
<Description>A cross-platform memory efficient serialization library</Description>
|
||||||
<PackageVersion>22.10.26</PackageVersion>
|
<PackageVersion>23.1.20</PackageVersion>
|
||||||
<Authors>Google LLC</Authors>
|
<Authors>Google LLC</Authors>
|
||||||
<PackageProjectUrl>https://github.com/google/flatbuffers</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/google/flatbuffers</PackageProjectUrl>
|
||||||
<RepositoryUrl>https://github.com/google/flatbuffers</RepositoryUrl>
|
<RepositoryUrl>https://github.com/google/flatbuffers</RepositoryUrl>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "flatbuffers",
|
"name": "flatbuffers",
|
||||||
"version": "22.10.26",
|
"version": "23.1.20",
|
||||||
"description": "Memory Efficient Serialization Library",
|
"description": "Memory Efficient Serialization Library",
|
||||||
"files": [
|
"files": [
|
||||||
"js/**/*.js",
|
"js/**/*.js",
|
||||||
|
|||||||
@@ -486,7 +486,12 @@ class ByteBuffer
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static function validateValue($min, $max, $value, $type, $additional_notes = "") {
|
private static function validateValue($min, $max, $value, $type, $additional_notes = "") {
|
||||||
if(!($min <= $value && $value <= $max)) {
|
if (
|
||||||
|
!(
|
||||||
|
($type === "byte" && $min <= ord($value) && ord($value) <= $max) ||
|
||||||
|
($min <= $value && $value <= $max)
|
||||||
|
)
|
||||||
|
) {
|
||||||
throw new \InvalidArgumentException(sprintf("bad number %s for type %s.%s", $value, $type, $additional_notes));
|
throw new \InvalidArgumentException(sprintf("bad number %s for type %s.%s", $value, $type, $additional_notes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,4 +14,4 @@
|
|||||||
|
|
||||||
# Placeholder, to be updated during the release process
|
# Placeholder, to be updated during the release process
|
||||||
# by the setup.py
|
# by the setup.py
|
||||||
__version__ = u"22.10.26"
|
__version__ = u"23.1.20"
|
||||||
|
|||||||
@@ -112,7 +112,8 @@ class Builder(object):
|
|||||||
|
|
||||||
## @cond FLATBUFFERS_INTENRAL
|
## @cond FLATBUFFERS_INTENRAL
|
||||||
__slots__ = ("Bytes", "current_vtable", "head", "minalign", "objectEnd",
|
__slots__ = ("Bytes", "current_vtable", "head", "minalign", "objectEnd",
|
||||||
"vtables", "nested", "forceDefaults", "finished", "vectorNumElems")
|
"vtables", "nested", "forceDefaults", "finished", "vectorNumElems",
|
||||||
|
"sharedStrings")
|
||||||
|
|
||||||
"""Maximum buffer size constant, in bytes.
|
"""Maximum buffer size constant, in bytes.
|
||||||
|
|
||||||
@@ -141,6 +142,7 @@ class Builder(object):
|
|||||||
self.vtables = {}
|
self.vtables = {}
|
||||||
self.nested = False
|
self.nested = False
|
||||||
self.forceDefaults = False
|
self.forceDefaults = False
|
||||||
|
self.sharedStrings = {}
|
||||||
## @endcond
|
## @endcond
|
||||||
self.finished = False
|
self.finished = False
|
||||||
|
|
||||||
@@ -405,6 +407,20 @@ class Builder(object):
|
|||||||
self.vectorNumElems = None
|
self.vectorNumElems = None
|
||||||
return self.Offset()
|
return self.Offset()
|
||||||
|
|
||||||
|
def CreateSharedString(self, s, encoding='utf-8', errors='strict'):
|
||||||
|
"""
|
||||||
|
CreateSharedString checks if the string is already written to the buffer
|
||||||
|
before calling CreateString.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if s in self.sharedStrings:
|
||||||
|
return self.sharedStrings[s]
|
||||||
|
|
||||||
|
off = self.CreateString(s, encoding, errors)
|
||||||
|
self.sharedStrings[s] = off
|
||||||
|
|
||||||
|
return off
|
||||||
|
|
||||||
def CreateString(self, s, encoding='utf-8', errors='strict'):
|
def CreateString(self, s, encoding='utf-8', errors='strict'):
|
||||||
"""CreateString writes a null-terminated byte string as a vector."""
|
"""CreateString writes a null-terminated byte string as a vector."""
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class BitWidth(enum.IntEnum):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def F(value):
|
def F(value):
|
||||||
"""Returns the `BitWidth` to encode floating point 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.W32
|
||||||
return BitWidth.W64
|
return BitWidth.W64
|
||||||
|
|
||||||
@@ -95,20 +95,20 @@ F = {4: 'f', 8: 'd'} # Floating point formats
|
|||||||
|
|
||||||
|
|
||||||
def _Unpack(fmt, buf):
|
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):
|
def _UnpackVector(fmt, buf, length):
|
||||||
byte_width = len(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):
|
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):
|
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):
|
def _Mutate(fmt, buf, value, byte_width, value_bit_width):
|
||||||
@@ -727,6 +727,15 @@ class Ref:
|
|||||||
def IsString(self):
|
def IsString(self):
|
||||||
return self._type is Type.STRING
|
return self._type is Type.STRING
|
||||||
|
|
||||||
|
@property
|
||||||
|
def AsStringBytes(self):
|
||||||
|
if self.IsString:
|
||||||
|
return String(self._Indirect(), self._byte_width).Bytes
|
||||||
|
elif self.IsKey:
|
||||||
|
return self.AsKeyBytes
|
||||||
|
else:
|
||||||
|
raise self._ConvertError(Type.STRING)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def AsString(self):
|
def AsString(self):
|
||||||
if self.IsString:
|
if self.IsString:
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
[bdist_wheel]
|
[bdist_wheel]
|
||||||
universal=1
|
universal=1
|
||||||
|
|
||||||
|
[metadata]
|
||||||
|
license_files =
|
||||||
|
../license.txt
|
||||||
@@ -16,8 +16,9 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='flatbuffers',
|
name='flatbuffers',
|
||||||
version='22.10.26',
|
version='23.1.20',
|
||||||
license='Apache 2.0',
|
license='Apache 2.0',
|
||||||
|
license_files='../LICENSE.txt',
|
||||||
author='Derek Bailey',
|
author='Derek Bailey',
|
||||||
author_email='derekbailey@google.com',
|
author_email='derekbailey@google.com',
|
||||||
url='https://google.github.io/flatbuffers/',
|
url='https://google.github.io/flatbuffers/',
|
||||||
|
|||||||
10
readme.md
10
readme.md
@@ -2,6 +2,7 @@
|
|||||||
===========
|
===========
|
||||||
|
|
||||||

|

|
||||||
|
[](https://buildkite.com/bazel/flatbuffers)
|
||||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:flatbuffers)
|
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:flatbuffers)
|
||||||
[](https://api.securityscorecards.dev/projects/github.com/google/flatbuffers)
|
[](https://api.securityscorecards.dev/projects/github.com/google/flatbuffers)
|
||||||
[](https://gitter.im/google/flatbuffers?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
[](https://gitter.im/google/flatbuffers?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
@@ -17,7 +18,7 @@ maximum memory efficiency. It allows you to directly access serialized data with
|
|||||||
|
|
||||||
## Supported operating systems
|
## Supported operating systems
|
||||||
* Windows
|
* Windows
|
||||||
* MacOS X
|
* macOS
|
||||||
* Linux
|
* Linux
|
||||||
* Android
|
* Android
|
||||||
* And any others with a recent C++ compiler (C++ 11 and newer)
|
* And any others with a recent C++ compiler (C++ 11 and newer)
|
||||||
@@ -39,12 +40,13 @@ Code generation and runtime libraries for many popular languages.
|
|||||||
1. PHP
|
1. PHP
|
||||||
1. Python - [PyPi](https://pypi.org/project/flatbuffers/)
|
1. Python - [PyPi](https://pypi.org/project/flatbuffers/)
|
||||||
1. Rust - [crates.io](https://crates.io/crates/flatbuffers)
|
1. Rust - [crates.io](https://crates.io/crates/flatbuffers)
|
||||||
1. Swift
|
1. Swift - [swiftpackageindex](https://swiftpackageindex.com/google/flatbuffers)
|
||||||
1. TypeScript - [NPM](https://www.npmjs.com/package/flatbuffers)
|
1. TypeScript - [NPM](https://www.npmjs.com/package/flatbuffers)
|
||||||
|
1. Nim
|
||||||
|
|
||||||
*and more in progress...*
|
## Versioning
|
||||||
|
|
||||||
1. [Nim](https://github.com/google/flatbuffers/pull/7362)
|
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
|
## Contribution
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "flatbuffers"
|
name = "flatbuffers"
|
||||||
version = "22.9.29"
|
version = "23.1.20"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
authors = ["Robert Winslow <hello@rwinslow.com>", "FlatBuffers Maintainers"]
|
authors = ["Robert Winslow <hello@rwinslow.com>", "FlatBuffers Maintainers"]
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
|||||||
@@ -25,6 +25,16 @@ pub struct Table<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Table<'a> {
|
impl<'a> Table<'a> {
|
||||||
|
#[inline]
|
||||||
|
pub fn buf(&self) -> &'a [u8] {
|
||||||
|
self.buf
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn loc(&self) -> usize {
|
||||||
|
self.loc
|
||||||
|
}
|
||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// `buf` must contain a `soffset_t` at `loc`, which points to a valid vtable
|
/// `buf` must contain a `soffset_t` at `loc`, which points to a valid vtable
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
// To run, use the `csharp_sample.sh` script.
|
// To run, use the `csharp_sample.sh` script.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using FlatBuffers;
|
using Google.FlatBuffers;
|
||||||
using MyGame.Sample;
|
using MyGame.Sample;
|
||||||
|
|
||||||
class SampleBinary
|
class SampleBinary
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import MyGame.Sample.Weapon
|
|||||||
|
|
||||||
import com.google.flatbuffers.FlatBufferBuilder
|
import com.google.flatbuffers.FlatBufferBuilder
|
||||||
|
|
||||||
|
@kotlin.ExperimentalUnsignedTypes
|
||||||
class SampleBinary {
|
class SampleBinary {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -45,7 +46,7 @@ class SampleBinary {
|
|||||||
|
|
||||||
// Serialize the FlatBuffer data.
|
// Serialize the FlatBuffer data.
|
||||||
val name = builder.createString("Orc")
|
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 inv = Monster.createInventoryVector(builder, treasure)
|
||||||
val weapons = Monster.createWeaponsVector(builder, weaps)
|
val weapons = Monster.createWeaponsVector(builder, weaps)
|
||||||
val pos = Vec3.createVec3(builder, 1.0f, 2.0f, 3.0f)
|
val pos = Vec3.createVec3(builder, 1.0f, 2.0f, 3.0f)
|
||||||
@@ -85,7 +86,7 @@ class SampleBinary {
|
|||||||
|
|
||||||
// Get and test the `inventory` FlatBuffer `vector`.
|
// Get and test the `inventory` FlatBuffer `vector`.
|
||||||
for (i in 0 until monster.inventoryLength) {
|
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.
|
// Get and test the `weapons` FlatBuffer `vector` of `table`s.
|
||||||
|
|||||||
Binary file not shown.
@@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||||
// generated, otherwise it may not be compatible.
|
// generated, otherwise it may not be compatible.
|
||||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 22 &&
|
static_assert(FLATBUFFERS_VERSION_MAJOR == 23 &&
|
||||||
FLATBUFFERS_VERSION_MINOR == 10 &&
|
FLATBUFFERS_VERSION_MINOR == 1 &&
|
||||||
FLATBUFFERS_VERSION_REVISION == 26,
|
FLATBUFFERS_VERSION_REVISION == 20,
|
||||||
"Non-compatible flatbuffers version included");
|
"Non-compatible flatbuffers version included");
|
||||||
|
|
||||||
namespace MyGame {
|
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);
|
||||||
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 {
|
enum Color : int8_t {
|
||||||
Color_Red = 0,
|
Color_Red = 0,
|
||||||
@@ -67,7 +67,7 @@ inline const char * const *EnumNamesColor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline const char *EnumNameColor(Color e) {
|
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);
|
const size_t index = static_cast<size_t>(e);
|
||||||
return EnumNamesColor()[index];
|
return EnumNamesColor()[index];
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ inline const char * const *EnumNamesEquipment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline const char *EnumNameEquipment(Equipment e) {
|
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);
|
const size_t index = static_cast<size_t>(e);
|
||||||
return EnumNamesEquipment()[index];
|
return EnumNamesEquipment()[index];
|
||||||
}
|
}
|
||||||
@@ -145,8 +145,8 @@ struct EquipmentUnion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *UnPack(const void *obj, Equipment type, const flatbuffers::resolver_function_t *resolver);
|
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;
|
::flatbuffers::Offset<void> Pack(::flatbuffers::FlatBufferBuilder &_fbb, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
|
||||||
|
|
||||||
MyGame::Sample::WeaponT *AsWeapon() {
|
MyGame::Sample::WeaponT *AsWeapon() {
|
||||||
return type == Equipment_Weapon ?
|
return type == Equipment_Weapon ?
|
||||||
@@ -179,8 +179,8 @@ inline bool operator!=(const EquipmentUnion &lhs, const EquipmentUnion &rhs) {
|
|||||||
return !(lhs == rhs);
|
return !(lhs == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VerifyEquipment(flatbuffers::Verifier &verifier, const void *obj, Equipment type);
|
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 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 {
|
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Vec3 FLATBUFFERS_FINAL_CLASS {
|
||||||
private:
|
private:
|
||||||
@@ -189,7 +189,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Vec3 FLATBUFFERS_FINAL_CLASS {
|
|||||||
float z_;
|
float z_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
|
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||||
return Vec3TypeTable();
|
return Vec3TypeTable();
|
||||||
}
|
}
|
||||||
Vec3()
|
Vec3()
|
||||||
@@ -198,27 +198,27 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Vec3 FLATBUFFERS_FINAL_CLASS {
|
|||||||
z_(0) {
|
z_(0) {
|
||||||
}
|
}
|
||||||
Vec3(float _x, float _y, float _z)
|
Vec3(float _x, float _y, float _z)
|
||||||
: x_(flatbuffers::EndianScalar(_x)),
|
: x_(::flatbuffers::EndianScalar(_x)),
|
||||||
y_(flatbuffers::EndianScalar(_y)),
|
y_(::flatbuffers::EndianScalar(_y)),
|
||||||
z_(flatbuffers::EndianScalar(_z)) {
|
z_(::flatbuffers::EndianScalar(_z)) {
|
||||||
}
|
}
|
||||||
float x() const {
|
float x() const {
|
||||||
return flatbuffers::EndianScalar(x_);
|
return ::flatbuffers::EndianScalar(x_);
|
||||||
}
|
}
|
||||||
void mutate_x(float _x) {
|
void mutate_x(float _x) {
|
||||||
flatbuffers::WriteScalar(&x_, _x);
|
::flatbuffers::WriteScalar(&x_, _x);
|
||||||
}
|
}
|
||||||
float y() const {
|
float y() const {
|
||||||
return flatbuffers::EndianScalar(y_);
|
return ::flatbuffers::EndianScalar(y_);
|
||||||
}
|
}
|
||||||
void mutate_y(float _y) {
|
void mutate_y(float _y) {
|
||||||
flatbuffers::WriteScalar(&y_, _y);
|
::flatbuffers::WriteScalar(&y_, _y);
|
||||||
}
|
}
|
||||||
float z() const {
|
float z() const {
|
||||||
return flatbuffers::EndianScalar(z_);
|
return ::flatbuffers::EndianScalar(z_);
|
||||||
}
|
}
|
||||||
void mutate_z(float _z) {
|
void mutate_z(float _z) {
|
||||||
flatbuffers::WriteScalar(&z_, _z);
|
::flatbuffers::WriteScalar(&z_, _z);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
FLATBUFFERS_STRUCT_END(Vec3, 12);
|
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;
|
typedef Monster TableType;
|
||||||
flatbuffers::unique_ptr<MyGame::Sample::Vec3> pos{};
|
flatbuffers::unique_ptr<MyGame::Sample::Vec3> pos{};
|
||||||
int16_t mana = 150;
|
int16_t mana = 150;
|
||||||
@@ -252,10 +252,10 @@ struct MonsterT : public flatbuffers::NativeTable {
|
|||||||
MonsterT &operator=(MonsterT o) FLATBUFFERS_NOEXCEPT;
|
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 MonsterT NativeTableType;
|
||||||
typedef MonsterBuilder Builder;
|
typedef MonsterBuilder Builder;
|
||||||
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
|
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||||
return MonsterTypeTable();
|
return MonsterTypeTable();
|
||||||
}
|
}
|
||||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
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) {
|
bool mutate_hp(int16_t _hp = 100) {
|
||||||
return SetField<int16_t>(VT_HP, _hp, 100);
|
return SetField<int16_t>(VT_HP, _hp, 100);
|
||||||
}
|
}
|
||||||
const flatbuffers::String *name() const {
|
const ::flatbuffers::String *name() const {
|
||||||
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
return GetPointer<const ::flatbuffers::String *>(VT_NAME);
|
||||||
}
|
}
|
||||||
flatbuffers::String *mutable_name() {
|
::flatbuffers::String *mutable_name() {
|
||||||
return GetPointer<flatbuffers::String *>(VT_NAME);
|
return GetPointer<::flatbuffers::String *>(VT_NAME);
|
||||||
}
|
}
|
||||||
const flatbuffers::Vector<uint8_t> *inventory() const {
|
const ::flatbuffers::Vector<uint8_t> *inventory() const {
|
||||||
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_INVENTORY);
|
return GetPointer<const ::flatbuffers::Vector<uint8_t> *>(VT_INVENTORY);
|
||||||
}
|
}
|
||||||
flatbuffers::Vector<uint8_t> *mutable_inventory() {
|
::flatbuffers::Vector<uint8_t> *mutable_inventory() {
|
||||||
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_INVENTORY);
|
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_INVENTORY);
|
||||||
}
|
}
|
||||||
MyGame::Sample::Color color() const {
|
MyGame::Sample::Color color() const {
|
||||||
return static_cast<MyGame::Sample::Color>(GetField<int8_t>(VT_COLOR, 2));
|
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)) {
|
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);
|
return SetField<int8_t>(VT_COLOR, static_cast<int8_t>(_color), 2);
|
||||||
}
|
}
|
||||||
const flatbuffers::Vector<flatbuffers::Offset<MyGame::Sample::Weapon>> *weapons() const {
|
const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Sample::Weapon>> *weapons() const {
|
||||||
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<MyGame::Sample::Weapon>> *>(VT_WEAPONS);
|
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Sample::Weapon>> *>(VT_WEAPONS);
|
||||||
}
|
}
|
||||||
flatbuffers::Vector<flatbuffers::Offset<MyGame::Sample::Weapon>> *mutable_weapons() {
|
::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Sample::Weapon>> *mutable_weapons() {
|
||||||
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<MyGame::Sample::Weapon>> *>(VT_WEAPONS);
|
return GetPointer<::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Sample::Weapon>> *>(VT_WEAPONS);
|
||||||
}
|
}
|
||||||
MyGame::Sample::Equipment equipped_type() const {
|
MyGame::Sample::Equipment equipped_type() const {
|
||||||
return static_cast<MyGame::Sample::Equipment>(GetField<uint8_t>(VT_EQUIPPED_TYPE, 0));
|
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() {
|
void *mutable_equipped() {
|
||||||
return GetPointer<void *>(VT_EQUIPPED);
|
return GetPointer<void *>(VT_EQUIPPED);
|
||||||
}
|
}
|
||||||
const flatbuffers::Vector<const MyGame::Sample::Vec3 *> *path() const {
|
const ::flatbuffers::Vector<const MyGame::Sample::Vec3 *> *path() const {
|
||||||
return GetPointer<const flatbuffers::Vector<const MyGame::Sample::Vec3 *> *>(VT_PATH);
|
return GetPointer<const ::flatbuffers::Vector<const MyGame::Sample::Vec3 *> *>(VT_PATH);
|
||||||
}
|
}
|
||||||
flatbuffers::Vector<const MyGame::Sample::Vec3 *> *mutable_path() {
|
::flatbuffers::Vector<const MyGame::Sample::Vec3 *> *mutable_path() {
|
||||||
return GetPointer<flatbuffers::Vector<const MyGame::Sample::Vec3 *> *>(VT_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) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyField<MyGame::Sample::Vec3>(verifier, VT_POS, 4) &&
|
VerifyField<MyGame::Sample::Vec3>(verifier, VT_POS, 4) &&
|
||||||
VerifyField<int16_t>(verifier, VT_MANA, 2) &&
|
VerifyField<int16_t>(verifier, VT_MANA, 2) &&
|
||||||
@@ -351,9 +351,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
verifier.VerifyVector(path()) &&
|
verifier.VerifyVector(path()) &&
|
||||||
verifier.EndTable();
|
verifier.EndTable();
|
||||||
}
|
}
|
||||||
MonsterT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
MonsterT *UnPack(const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||||
void UnPackTo(MonsterT *_o, 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);
|
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 {
|
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 {
|
struct MonsterBuilder {
|
||||||
typedef Monster Table;
|
typedef Monster Table;
|
||||||
flatbuffers::FlatBufferBuilder &fbb_;
|
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
flatbuffers::uoffset_t start_;
|
::flatbuffers::uoffset_t start_;
|
||||||
void add_pos(const MyGame::Sample::Vec3 *pos) {
|
void add_pos(const MyGame::Sample::Vec3 *pos) {
|
||||||
fbb_.AddStruct(Monster::VT_POS, pos);
|
fbb_.AddStruct(Monster::VT_POS, pos);
|
||||||
}
|
}
|
||||||
@@ -373,50 +373,50 @@ struct MonsterBuilder {
|
|||||||
void add_hp(int16_t hp) {
|
void add_hp(int16_t hp) {
|
||||||
fbb_.AddElement<int16_t>(Monster::VT_HP, hp, 100);
|
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);
|
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);
|
fbb_.AddOffset(Monster::VT_INVENTORY, inventory);
|
||||||
}
|
}
|
||||||
void add_color(MyGame::Sample::Color color) {
|
void add_color(MyGame::Sample::Color color) {
|
||||||
fbb_.AddElement<int8_t>(Monster::VT_COLOR, static_cast<int8_t>(color), 2);
|
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);
|
fbb_.AddOffset(Monster::VT_WEAPONS, weapons);
|
||||||
}
|
}
|
||||||
void add_equipped_type(MyGame::Sample::Equipment equipped_type) {
|
void add_equipped_type(MyGame::Sample::Equipment equipped_type) {
|
||||||
fbb_.AddElement<uint8_t>(Monster::VT_EQUIPPED_TYPE, static_cast<uint8_t>(equipped_type), 0);
|
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);
|
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);
|
fbb_.AddOffset(Monster::VT_PATH, path);
|
||||||
}
|
}
|
||||||
explicit MonsterBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
explicit MonsterBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
: fbb_(_fbb) {
|
: fbb_(_fbb) {
|
||||||
start_ = fbb_.StartTable();
|
start_ = fbb_.StartTable();
|
||||||
}
|
}
|
||||||
flatbuffers::Offset<Monster> Finish() {
|
::flatbuffers::Offset<Monster> Finish() {
|
||||||
const auto end = fbb_.EndTable(start_);
|
const auto end = fbb_.EndTable(start_);
|
||||||
auto o = flatbuffers::Offset<Monster>(end);
|
auto o = ::flatbuffers::Offset<Monster>(end);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline flatbuffers::Offset<Monster> CreateMonster(
|
inline ::flatbuffers::Offset<Monster> CreateMonster(
|
||||||
flatbuffers::FlatBufferBuilder &_fbb,
|
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
const MyGame::Sample::Vec3 *pos = nullptr,
|
const MyGame::Sample::Vec3 *pos = nullptr,
|
||||||
int16_t mana = 150,
|
int16_t mana = 150,
|
||||||
int16_t hp = 100,
|
int16_t hp = 100,
|
||||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
::flatbuffers::Offset<::flatbuffers::String> name = 0,
|
||||||
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> inventory = 0,
|
::flatbuffers::Offset<::flatbuffers::Vector<uint8_t>> inventory = 0,
|
||||||
MyGame::Sample::Color color = MyGame::Sample::Color_Blue,
|
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,
|
MyGame::Sample::Equipment equipped_type = MyGame::Sample::Equipment_NONE,
|
||||||
flatbuffers::Offset<void> equipped = 0,
|
::flatbuffers::Offset<void> equipped = 0,
|
||||||
flatbuffers::Offset<flatbuffers::Vector<const MyGame::Sample::Vec3 *>> path = 0) {
|
::flatbuffers::Offset<::flatbuffers::Vector<const MyGame::Sample::Vec3 *>> path = 0) {
|
||||||
MonsterBuilder builder_(_fbb);
|
MonsterBuilder builder_(_fbb);
|
||||||
builder_.add_path(path);
|
builder_.add_path(path);
|
||||||
builder_.add_equipped(equipped);
|
builder_.add_equipped(equipped);
|
||||||
@@ -431,21 +431,21 @@ inline flatbuffers::Offset<Monster> CreateMonster(
|
|||||||
return builder_.Finish();
|
return builder_.Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline flatbuffers::Offset<Monster> CreateMonsterDirect(
|
inline ::flatbuffers::Offset<Monster> CreateMonsterDirect(
|
||||||
flatbuffers::FlatBufferBuilder &_fbb,
|
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
const MyGame::Sample::Vec3 *pos = nullptr,
|
const MyGame::Sample::Vec3 *pos = nullptr,
|
||||||
int16_t mana = 150,
|
int16_t mana = 150,
|
||||||
int16_t hp = 100,
|
int16_t hp = 100,
|
||||||
const char *name = nullptr,
|
const char *name = nullptr,
|
||||||
const std::vector<uint8_t> *inventory = nullptr,
|
const std::vector<uint8_t> *inventory = nullptr,
|
||||||
MyGame::Sample::Color color = MyGame::Sample::Color_Blue,
|
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,
|
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) {
|
const std::vector<MyGame::Sample::Vec3> *path = nullptr) {
|
||||||
auto name__ = name ? _fbb.CreateString(name) : 0;
|
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||||
auto inventory__ = inventory ? _fbb.CreateVector<uint8_t>(*inventory) : 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;
|
auto path__ = path ? _fbb.CreateVectorOfStructs<MyGame::Sample::Vec3>(*path) : 0;
|
||||||
return MyGame::Sample::CreateMonster(
|
return MyGame::Sample::CreateMonster(
|
||||||
_fbb,
|
_fbb,
|
||||||
@@ -461,29 +461,29 @@ inline flatbuffers::Offset<Monster> CreateMonsterDirect(
|
|||||||
path__);
|
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;
|
typedef Weapon TableType;
|
||||||
std::string name{};
|
std::string name{};
|
||||||
int16_t damage = 0;
|
int16_t damage = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Weapon FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
struct Weapon FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||||
typedef WeaponT NativeTableType;
|
typedef WeaponT NativeTableType;
|
||||||
typedef WeaponBuilder Builder;
|
typedef WeaponBuilder Builder;
|
||||||
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
|
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||||
return WeaponTypeTable();
|
return WeaponTypeTable();
|
||||||
}
|
}
|
||||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||||
VT_NAME = 4,
|
VT_NAME = 4,
|
||||||
VT_DAMAGE = 6
|
VT_DAMAGE = 6
|
||||||
};
|
};
|
||||||
const flatbuffers::String *name() const {
|
const ::flatbuffers::String *name() const {
|
||||||
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
return GetPointer<const ::flatbuffers::String *>(VT_NAME);
|
||||||
}
|
}
|
||||||
flatbuffers::String *mutable_name() {
|
::flatbuffers::String *mutable_name() {
|
||||||
return GetPointer<flatbuffers::String *>(VT_NAME);
|
return GetPointer<::flatbuffers::String *>(VT_NAME);
|
||||||
}
|
}
|
||||||
int16_t damage() const {
|
int16_t damage() const {
|
||||||
return GetField<int16_t>(VT_DAMAGE, 0);
|
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) {
|
bool mutate_damage(int16_t _damage = 0) {
|
||||||
return SetField<int16_t>(VT_DAMAGE, _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) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyOffset(verifier, VT_NAME) &&
|
VerifyOffset(verifier, VT_NAME) &&
|
||||||
verifier.VerifyString(name()) &&
|
verifier.VerifyString(name()) &&
|
||||||
VerifyField<int16_t>(verifier, VT_DAMAGE, 2) &&
|
VerifyField<int16_t>(verifier, VT_DAMAGE, 2) &&
|
||||||
verifier.EndTable();
|
verifier.EndTable();
|
||||||
}
|
}
|
||||||
WeaponT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
WeaponT *UnPack(const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||||
void UnPackTo(WeaponT *_o, 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);
|
static ::flatbuffers::Offset<Weapon> Pack(::flatbuffers::FlatBufferBuilder &_fbb, const WeaponT* _o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WeaponBuilder {
|
struct WeaponBuilder {
|
||||||
typedef Weapon Table;
|
typedef Weapon Table;
|
||||||
flatbuffers::FlatBufferBuilder &fbb_;
|
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
flatbuffers::uoffset_t start_;
|
::flatbuffers::uoffset_t start_;
|
||||||
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
void add_name(::flatbuffers::Offset<::flatbuffers::String> name) {
|
||||||
fbb_.AddOffset(Weapon::VT_NAME, name);
|
fbb_.AddOffset(Weapon::VT_NAME, name);
|
||||||
}
|
}
|
||||||
void add_damage(int16_t damage) {
|
void add_damage(int16_t damage) {
|
||||||
fbb_.AddElement<int16_t>(Weapon::VT_DAMAGE, damage, 0);
|
fbb_.AddElement<int16_t>(Weapon::VT_DAMAGE, damage, 0);
|
||||||
}
|
}
|
||||||
explicit WeaponBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
explicit WeaponBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
: fbb_(_fbb) {
|
: fbb_(_fbb) {
|
||||||
start_ = fbb_.StartTable();
|
start_ = fbb_.StartTable();
|
||||||
}
|
}
|
||||||
flatbuffers::Offset<Weapon> Finish() {
|
::flatbuffers::Offset<Weapon> Finish() {
|
||||||
const auto end = fbb_.EndTable(start_);
|
const auto end = fbb_.EndTable(start_);
|
||||||
auto o = flatbuffers::Offset<Weapon>(end);
|
auto o = ::flatbuffers::Offset<Weapon>(end);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline flatbuffers::Offset<Weapon> CreateWeapon(
|
inline ::flatbuffers::Offset<Weapon> CreateWeapon(
|
||||||
flatbuffers::FlatBufferBuilder &_fbb,
|
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
::flatbuffers::Offset<::flatbuffers::String> name = 0,
|
||||||
int16_t damage = 0) {
|
int16_t damage = 0) {
|
||||||
WeaponBuilder builder_(_fbb);
|
WeaponBuilder builder_(_fbb);
|
||||||
builder_.add_name(name);
|
builder_.add_name(name);
|
||||||
@@ -534,8 +534,8 @@ inline flatbuffers::Offset<Weapon> CreateWeapon(
|
|||||||
return builder_.Finish();
|
return builder_.Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline flatbuffers::Offset<Weapon> CreateWeaponDirect(
|
inline ::flatbuffers::Offset<Weapon> CreateWeaponDirect(
|
||||||
flatbuffers::FlatBufferBuilder &_fbb,
|
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
const char *name = nullptr,
|
const char *name = nullptr,
|
||||||
int16_t damage = 0) {
|
int16_t damage = 0) {
|
||||||
auto name__ = name ? _fbb.CreateString(name) : 0;
|
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||||
@@ -545,7 +545,7 @@ inline flatbuffers::Offset<Weapon> CreateWeaponDirect(
|
|||||||
damage);
|
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) {
|
inline bool operator==(const MonsterT &lhs, const MonsterT &rhs) {
|
||||||
@@ -592,13 +592,13 @@ inline MonsterT &MonsterT::operator=(MonsterT o) FLATBUFFERS_NOEXCEPT {
|
|||||||
return *this;
|
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());
|
auto _o = std::unique_ptr<MonsterT>(new MonsterT());
|
||||||
UnPackTo(_o.get(), _resolver);
|
UnPackTo(_o.get(), _resolver);
|
||||||
return _o.release();
|
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)_o;
|
||||||
(void)_resolver;
|
(void)_resolver;
|
||||||
{ auto _e = pos(); if (_e) _o->pos = flatbuffers::unique_ptr<MyGame::Sample::Vec3>(new MyGame::Sample::Vec3(*_e)); }
|
{ 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 = 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 = 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 = 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_type(); _o->equipped.type = _e; }
|
||||||
{ auto _e = equipped(); if (_e) _o->equipped.value = MyGame::Sample::EquipmentUnion::UnPack(_e, equipped_type(), _resolver); }
|
{ 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);
|
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)_rehasher;
|
||||||
(void)_o;
|
(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 _pos = _o->pos ? _o->pos.get() : nullptr;
|
||||||
auto _mana = _o->mana;
|
auto _mana = _o->mana;
|
||||||
auto _hp = _o->hp;
|
auto _hp = _o->hp;
|
||||||
auto _name = _o->name.empty() ? 0 : _fbb.CreateString(_o->name);
|
auto _name = _o->name.empty() ? 0 : _fbb.CreateString(_o->name);
|
||||||
auto _inventory = _o->inventory.size() ? _fbb.CreateVector(_o->inventory) : 0;
|
auto _inventory = _o->inventory.size() ? _fbb.CreateVector(_o->inventory) : 0;
|
||||||
auto _color = _o->color;
|
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_type = _o->equipped.type;
|
||||||
auto _equipped = _o->equipped.Pack(_fbb);
|
auto _equipped = _o->equipped.Pack(_fbb);
|
||||||
auto _path = _o->path.size() ? _fbb.CreateVectorOfStructs(_o->path) : 0;
|
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());
|
auto _o = std::unique_ptr<WeaponT>(new WeaponT());
|
||||||
UnPackTo(_o.get(), _resolver);
|
UnPackTo(_o.get(), _resolver);
|
||||||
return _o.release();
|
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)_o;
|
||||||
(void)_resolver;
|
(void)_resolver;
|
||||||
{ auto _e = name(); if (_e) _o->name = _e->str(); }
|
{ auto _e = name(); if (_e) _o->name = _e->str(); }
|
||||||
{ auto _e = damage(); _o->damage = _e; }
|
{ 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);
|
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)_rehasher;
|
||||||
(void)_o;
|
(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 _name = _o->name.empty() ? 0 : _fbb.CreateString(_o->name);
|
||||||
auto _damage = _o->damage;
|
auto _damage = _o->damage;
|
||||||
return MyGame::Sample::CreateWeapon(
|
return MyGame::Sample::CreateWeapon(
|
||||||
@@ -686,7 +686,7 @@ inline flatbuffers::Offset<Weapon> CreateWeapon(flatbuffers::FlatBufferBuilder &
|
|||||||
_damage);
|
_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) {
|
switch (type) {
|
||||||
case Equipment_NONE: {
|
case Equipment_NONE: {
|
||||||
return true;
|
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 || !types) return !values && !types;
|
||||||
if (values->size() != types->size()) return false;
|
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(
|
if (!VerifyEquipment(
|
||||||
verifier, values->Get(i), types->GetEnum<Equipment>(i))) {
|
verifier, values->Get(i), types->GetEnum<Equipment>(i))) {
|
||||||
return false;
|
return false;
|
||||||
@@ -711,7 +711,7 @@ inline bool VerifyEquipmentVector(flatbuffers::Verifier &verifier, const flatbuf
|
|||||||
return true;
|
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;
|
(void)resolver;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Equipment_Weapon: {
|
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;
|
(void)_rehasher;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Equipment_Weapon: {
|
case Equipment_Weapon: {
|
||||||
@@ -757,13 +757,13 @@ inline void EquipmentUnion::Reset() {
|
|||||||
type = Equipment_NONE;
|
type = Equipment_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const flatbuffers::TypeTable *ColorTypeTable() {
|
inline const ::flatbuffers::TypeTable *ColorTypeTable() {
|
||||||
static const flatbuffers::TypeCode type_codes[] = {
|
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||||
{ flatbuffers::ET_CHAR, 0, 0 },
|
{ ::flatbuffers::ET_CHAR, 0, 0 },
|
||||||
{ flatbuffers::ET_CHAR, 0, 0 },
|
{ ::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
|
MyGame::Sample::ColorTypeTable
|
||||||
};
|
};
|
||||||
static const char * const names[] = {
|
static const char * const names[] = {
|
||||||
@@ -771,35 +771,35 @@ inline const flatbuffers::TypeTable *ColorTypeTable() {
|
|||||||
"Green",
|
"Green",
|
||||||
"Blue"
|
"Blue"
|
||||||
};
|
};
|
||||||
static const flatbuffers::TypeTable tt = {
|
static const ::flatbuffers::TypeTable tt = {
|
||||||
flatbuffers::ST_ENUM, 3, type_codes, type_refs, nullptr, nullptr, names
|
::flatbuffers::ST_ENUM, 3, type_codes, type_refs, nullptr, nullptr, names
|
||||||
};
|
};
|
||||||
return &tt;
|
return &tt;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const flatbuffers::TypeTable *EquipmentTypeTable() {
|
inline const ::flatbuffers::TypeTable *EquipmentTypeTable() {
|
||||||
static const flatbuffers::TypeCode type_codes[] = {
|
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||||
{ flatbuffers::ET_SEQUENCE, 0, -1 },
|
{ ::flatbuffers::ET_SEQUENCE, 0, -1 },
|
||||||
{ flatbuffers::ET_SEQUENCE, 0, 0 }
|
{ ::flatbuffers::ET_SEQUENCE, 0, 0 }
|
||||||
};
|
};
|
||||||
static const flatbuffers::TypeFunction type_refs[] = {
|
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||||
MyGame::Sample::WeaponTypeTable
|
MyGame::Sample::WeaponTypeTable
|
||||||
};
|
};
|
||||||
static const char * const names[] = {
|
static const char * const names[] = {
|
||||||
"NONE",
|
"NONE",
|
||||||
"Weapon"
|
"Weapon"
|
||||||
};
|
};
|
||||||
static const flatbuffers::TypeTable tt = {
|
static const ::flatbuffers::TypeTable tt = {
|
||||||
flatbuffers::ST_UNION, 2, type_codes, type_refs, nullptr, nullptr, names
|
::flatbuffers::ST_UNION, 2, type_codes, type_refs, nullptr, nullptr, names
|
||||||
};
|
};
|
||||||
return &tt;
|
return &tt;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const flatbuffers::TypeTable *Vec3TypeTable() {
|
inline const ::flatbuffers::TypeTable *Vec3TypeTable() {
|
||||||
static const flatbuffers::TypeCode type_codes[] = {
|
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||||
{ flatbuffers::ET_FLOAT, 0, -1 },
|
{ ::flatbuffers::ET_FLOAT, 0, -1 },
|
||||||
{ flatbuffers::ET_FLOAT, 0, -1 },
|
{ ::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 int64_t values[] = { 0, 4, 8, 12 };
|
||||||
static const char * const names[] = {
|
static const char * const names[] = {
|
||||||
@@ -807,27 +807,27 @@ inline const flatbuffers::TypeTable *Vec3TypeTable() {
|
|||||||
"y",
|
"y",
|
||||||
"z"
|
"z"
|
||||||
};
|
};
|
||||||
static const flatbuffers::TypeTable tt = {
|
static const ::flatbuffers::TypeTable tt = {
|
||||||
flatbuffers::ST_STRUCT, 3, type_codes, nullptr, nullptr, values, names
|
::flatbuffers::ST_STRUCT, 3, type_codes, nullptr, nullptr, values, names
|
||||||
};
|
};
|
||||||
return &tt;
|
return &tt;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const flatbuffers::TypeTable *MonsterTypeTable() {
|
inline const ::flatbuffers::TypeTable *MonsterTypeTable() {
|
||||||
static const flatbuffers::TypeCode type_codes[] = {
|
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||||
{ flatbuffers::ET_SEQUENCE, 0, 0 },
|
{ ::flatbuffers::ET_SEQUENCE, 0, 0 },
|
||||||
{ flatbuffers::ET_SHORT, 0, -1 },
|
{ ::flatbuffers::ET_SHORT, 0, -1 },
|
||||||
{ flatbuffers::ET_SHORT, 0, -1 },
|
{ ::flatbuffers::ET_SHORT, 0, -1 },
|
||||||
{ flatbuffers::ET_STRING, 0, -1 },
|
{ ::flatbuffers::ET_STRING, 0, -1 },
|
||||||
{ flatbuffers::ET_BOOL, 0, -1 },
|
{ ::flatbuffers::ET_BOOL, 0, -1 },
|
||||||
{ flatbuffers::ET_UCHAR, 1, -1 },
|
{ ::flatbuffers::ET_UCHAR, 1, -1 },
|
||||||
{ flatbuffers::ET_CHAR, 0, 1 },
|
{ ::flatbuffers::ET_CHAR, 0, 1 },
|
||||||
{ flatbuffers::ET_SEQUENCE, 1, 2 },
|
{ ::flatbuffers::ET_SEQUENCE, 1, 2 },
|
||||||
{ flatbuffers::ET_UTYPE, 0, 3 },
|
{ ::flatbuffers::ET_UTYPE, 0, 3 },
|
||||||
{ flatbuffers::ET_SEQUENCE, 0, 3 },
|
{ ::flatbuffers::ET_SEQUENCE, 0, 3 },
|
||||||
{ flatbuffers::ET_SEQUENCE, 1, 0 }
|
{ ::flatbuffers::ET_SEQUENCE, 1, 0 }
|
||||||
};
|
};
|
||||||
static const flatbuffers::TypeFunction type_refs[] = {
|
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||||
MyGame::Sample::Vec3TypeTable,
|
MyGame::Sample::Vec3TypeTable,
|
||||||
MyGame::Sample::ColorTypeTable,
|
MyGame::Sample::ColorTypeTable,
|
||||||
MyGame::Sample::WeaponTypeTable,
|
MyGame::Sample::WeaponTypeTable,
|
||||||
@@ -846,74 +846,74 @@ inline const flatbuffers::TypeTable *MonsterTypeTable() {
|
|||||||
"equipped",
|
"equipped",
|
||||||
"path"
|
"path"
|
||||||
};
|
};
|
||||||
static const flatbuffers::TypeTable tt = {
|
static const ::flatbuffers::TypeTable tt = {
|
||||||
flatbuffers::ST_TABLE, 11, type_codes, type_refs, nullptr, nullptr, names
|
::flatbuffers::ST_TABLE, 11, type_codes, type_refs, nullptr, nullptr, names
|
||||||
};
|
};
|
||||||
return &tt;
|
return &tt;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const flatbuffers::TypeTable *WeaponTypeTable() {
|
inline const ::flatbuffers::TypeTable *WeaponTypeTable() {
|
||||||
static const flatbuffers::TypeCode type_codes[] = {
|
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||||
{ flatbuffers::ET_STRING, 0, -1 },
|
{ ::flatbuffers::ET_STRING, 0, -1 },
|
||||||
{ flatbuffers::ET_SHORT, 0, -1 }
|
{ ::flatbuffers::ET_SHORT, 0, -1 }
|
||||||
};
|
};
|
||||||
static const char * const names[] = {
|
static const char * const names[] = {
|
||||||
"name",
|
"name",
|
||||||
"damage"
|
"damage"
|
||||||
};
|
};
|
||||||
static const flatbuffers::TypeTable tt = {
|
static const ::flatbuffers::TypeTable tt = {
|
||||||
flatbuffers::ST_TABLE, 2, type_codes, nullptr, nullptr, nullptr, names
|
::flatbuffers::ST_TABLE, 2, type_codes, nullptr, nullptr, nullptr, names
|
||||||
};
|
};
|
||||||
return &tt;
|
return &tt;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const MyGame::Sample::Monster *GetMonster(const void *buf) {
|
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) {
|
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) {
|
inline Monster *GetMutableMonster(void *buf) {
|
||||||
return flatbuffers::GetMutableRoot<Monster>(buf);
|
return ::flatbuffers::GetMutableRoot<Monster>(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline MyGame::Sample::Monster *GetMutableSizePrefixedMonster(void *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(
|
inline bool VerifyMonsterBuffer(
|
||||||
flatbuffers::Verifier &verifier) {
|
::flatbuffers::Verifier &verifier) {
|
||||||
return verifier.VerifyBuffer<MyGame::Sample::Monster>(nullptr);
|
return verifier.VerifyBuffer<MyGame::Sample::Monster>(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool VerifySizePrefixedMonsterBuffer(
|
inline bool VerifySizePrefixedMonsterBuffer(
|
||||||
flatbuffers::Verifier &verifier) {
|
::flatbuffers::Verifier &verifier) {
|
||||||
return verifier.VerifySizePrefixedBuffer<MyGame::Sample::Monster>(nullptr);
|
return verifier.VerifySizePrefixedBuffer<MyGame::Sample::Monster>(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void FinishMonsterBuffer(
|
inline void FinishMonsterBuffer(
|
||||||
flatbuffers::FlatBufferBuilder &fbb,
|
::flatbuffers::FlatBufferBuilder &fbb,
|
||||||
flatbuffers::Offset<MyGame::Sample::Monster> root) {
|
::flatbuffers::Offset<MyGame::Sample::Monster> root) {
|
||||||
fbb.Finish(root);
|
fbb.Finish(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void FinishSizePrefixedMonsterBuffer(
|
inline void FinishSizePrefixedMonsterBuffer(
|
||||||
flatbuffers::FlatBufferBuilder &fbb,
|
::flatbuffers::FlatBufferBuilder &fbb,
|
||||||
flatbuffers::Offset<MyGame::Sample::Monster> root) {
|
::flatbuffers::Offset<MyGame::Sample::Monster> root) {
|
||||||
fbb.FinishSizePrefixed(root);
|
fbb.FinishSizePrefixed(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline flatbuffers::unique_ptr<MyGame::Sample::MonsterT> UnPackMonster(
|
inline flatbuffers::unique_ptr<MyGame::Sample::MonsterT> UnPackMonster(
|
||||||
const void *buf,
|
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));
|
return flatbuffers::unique_ptr<MyGame::Sample::MonsterT>(GetMonster(buf)->UnPack(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline flatbuffers::unique_ptr<MyGame::Sample::MonsterT> UnPackSizePrefixedMonster(
|
inline flatbuffers::unique_ptr<MyGame::Sample::MonsterT> UnPackSizePrefixedMonster(
|
||||||
const void *buf,
|
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));
|
return flatbuffers::unique_ptr<MyGame::Sample::MonsterT>(GetSizePrefixedMonster(buf)->UnPack(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
import FlatBuffers
|
import FlatBuffers
|
||||||
|
|
||||||
public enum MyGame_Sample_Color: Int8, Enum {
|
public enum MyGame_Sample_Color: Int8, Enum, Verifiable {
|
||||||
public typealias T = Int8
|
public typealias T = Int8
|
||||||
public static var byteSize: Int { return MemoryLayout<Int8>.size }
|
public static var byteSize: Int { return MemoryLayout<Int8>.size }
|
||||||
public var value: Int8 { return self.rawValue }
|
public var value: Int8 { return self.rawValue }
|
||||||
@@ -12,31 +12,43 @@ public enum MyGame_Sample_Color: Int8, Enum {
|
|||||||
case green = 1
|
case green = 1
|
||||||
case blue = 2
|
case blue = 2
|
||||||
|
|
||||||
|
|
||||||
public static var max: MyGame_Sample_Color { return .blue }
|
public static var max: MyGame_Sample_Color { return .blue }
|
||||||
public static var min: MyGame_Sample_Color { return .red }
|
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 typealias T = UInt8
|
||||||
|
|
||||||
|
public init?(value: T) {
|
||||||
|
self.init(rawValue: value)
|
||||||
|
}
|
||||||
|
|
||||||
public static var byteSize: Int { return MemoryLayout<UInt8>.size }
|
public static var byteSize: Int { return MemoryLayout<UInt8>.size }
|
||||||
public var value: UInt8 { return self.rawValue }
|
public var value: UInt8 { return self.rawValue }
|
||||||
case none_ = 0
|
case none_ = 0
|
||||||
case weapon = 1
|
case weapon = 1
|
||||||
|
|
||||||
|
|
||||||
public static var max: MyGame_Sample_Equipment { return .weapon }
|
public static var max: MyGame_Sample_Equipment { return .weapon }
|
||||||
public static var min: MyGame_Sample_Equipment { return .none_ }
|
public static var min: MyGame_Sample_Equipment { return .none_ }
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct MyGame_Sample_Vec3: NativeStruct {
|
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_22_10_26() }
|
public struct MyGame_Sample_Vec3: NativeStruct, Verifiable, FlatbuffersInitializable {
|
||||||
|
|
||||||
|
static func validateVersion() { FlatBuffersVersion_23_1_20() }
|
||||||
|
|
||||||
private var _x: Float32
|
private var _x: Float32
|
||||||
private var _y: Float32
|
private var _y: Float32
|
||||||
private var _z: 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) {
|
public init(x: Float32, y: Float32, z: Float32) {
|
||||||
_x = x
|
_x = x
|
||||||
_y = y
|
_y = y
|
||||||
@@ -52,11 +64,15 @@ public struct MyGame_Sample_Vec3: NativeStruct {
|
|||||||
public var x: Float32 { _x }
|
public var x: Float32 { _x }
|
||||||
public var y: Float32 { _y }
|
public var y: Float32 { _y }
|
||||||
public var z: Float32 { _z }
|
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 {
|
public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_22_10_26() }
|
static func validateVersion() { FlatBuffersVersion_23_1_20() }
|
||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Struct
|
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) }
|
@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_22_10_26() }
|
static func validateVersion() { FlatBuffersVersion_23_1_20() }
|
||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
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 }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
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) }
|
@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 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 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 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 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 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 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 }
|
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) }
|
@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 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 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 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 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 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 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) }
|
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)
|
MyGame_Sample_Monster.addVectorOf(path: path, &fbb)
|
||||||
return MyGame_Sample_Monster.endMonster(&fbb, start: __start)
|
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_22_10_26() }
|
static func validateVersion() { FlatBuffersVersion_23_1_20() }
|
||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
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 }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
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)
|
MyGame_Sample_Weapon.add(damage: damage, &fbb)
|
||||||
return MyGame_Sample_Weapon.endWeapon(&fbb, start: __start)
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -56,8 +56,8 @@ func main() {
|
|||||||
equippedOffset: axe)
|
equippedOffset: axe)
|
||||||
builder.finish(offset: orc)
|
builder.finish(offset: orc)
|
||||||
|
|
||||||
let buf = builder.sizedByteArray
|
var buf = ByteBuffer(bytes: builder.sizedByteArray)
|
||||||
let monster = Monster.getRootAsMonster(bb: ByteBuffer(bytes: buf))
|
let monster: Monster = try! getCheckedRoot(byteBuffer: &buffer)
|
||||||
|
|
||||||
assert(monster.mana == 150)
|
assert(monster.mana == 150)
|
||||||
assert(monster.hp == 300)
|
assert(monster.hp == 300)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ root_path = script_path.parent.absolute()
|
|||||||
print("Generating GRPC code...")
|
print("Generating GRPC code...")
|
||||||
generate_grpc_examples.GenerateGRPCExamples()
|
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:
|
if result.returncode != 0:
|
||||||
print(
|
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.
|
# Get the root path as an absolute path, so all derived paths are absolute.
|
||||||
root_path = script_path.parent.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:
|
if result.returncode != 0:
|
||||||
print(
|
print(
|
||||||
@@ -46,7 +46,7 @@ if platform.system() == "Windows":
|
|||||||
gen_cmd = ["py"] + gen_cmd
|
gen_cmd = ["py"] + gen_cmd
|
||||||
subprocess.run(gen_cmd, cwd=root_path)
|
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:
|
if result.returncode != 0:
|
||||||
print(
|
print(
|
||||||
|
|||||||
1
scripts/clang-tidy-git.sh
Executable file
1
scripts/clang-tidy-git.sh
Executable file
@@ -0,0 +1 @@
|
|||||||
|
run-clang-tidy -fix -extra-arg=-std=c++11 -extra-arg=-Wno-unknown-warning-option `git diff --name-only origin/HEAD`
|
||||||
@@ -14,73 +14,19 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import argparse
|
|
||||||
import filecmp
|
import filecmp
|
||||||
import glob
|
import glob
|
||||||
import platform
|
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import generate_grpc_examples
|
import generate_grpc_examples
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from util import flatc, root_path, tests_path, args, flatc_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)
|
|
||||||
|
|
||||||
# Specify the other paths that will be referenced
|
# Specify the other paths that will be referenced
|
||||||
tests_path = Path(root_path, "tests")
|
|
||||||
swift_code_gen = Path(root_path, "tests/swift/tests/CodeGenerationTests")
|
swift_code_gen = Path(root_path, "tests/swift/tests/CodeGenerationTests")
|
||||||
samples_path = Path(root_path, "samples")
|
samples_path = Path(root_path, "samples")
|
||||||
reflection_path = Path(root_path, "reflection")
|
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
|
# Generate the code for flatbuffers reflection schema
|
||||||
def flatc_reflection(options, location, target):
|
def flatc_reflection(options, location, target):
|
||||||
full_options = ["--no-prefix"] + options
|
full_options = ["--no-prefix"] + options
|
||||||
@@ -150,7 +96,7 @@ SWIFT_OPTS_CODE_GEN = [
|
|||||||
"--swift",
|
"--swift",
|
||||||
"--gen-json-emit",
|
"--gen-json-emit",
|
||||||
"--bfbs-filenames",
|
"--bfbs-filenames",
|
||||||
swift_code_gen
|
str(swift_code_gen)
|
||||||
]
|
]
|
||||||
JAVA_OPTS = ["--java"]
|
JAVA_OPTS = ["--java"]
|
||||||
KOTLIN_OPTS = ["--kotlin"]
|
KOTLIN_OPTS = ["--kotlin"]
|
||||||
@@ -179,6 +125,20 @@ flatc(
|
|||||||
data="monsterdata_test.json",
|
data="monsterdata_test.json",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
flatc(
|
||||||
|
NO_INCL_OPTS
|
||||||
|
+ DART_OPTS,
|
||||||
|
schema="include_test/include_test1.fbs",
|
||||||
|
include="include_test/sub",
|
||||||
|
)
|
||||||
|
|
||||||
|
flatc(
|
||||||
|
NO_INCL_OPTS
|
||||||
|
+ DART_OPTS,
|
||||||
|
schema="include_test/sub/include_test2.fbs",
|
||||||
|
include="include_test",
|
||||||
|
)
|
||||||
|
|
||||||
flatc(
|
flatc(
|
||||||
NO_INCL_OPTS
|
NO_INCL_OPTS
|
||||||
+ TS_OPTS,
|
+ TS_OPTS,
|
||||||
@@ -393,6 +353,13 @@ type_field_collsion_schema = "type_field_collsion.fbs"
|
|||||||
|
|
||||||
flatc(["--csharp", "--gen-object-api"], schema=type_field_collsion_schema)
|
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
|
# Generate string/vector default code for tests
|
||||||
flatc(RUST_OPTS, prefix="more_defaults", schema="more_defaults.fbs")
|
flatc(RUST_OPTS, prefix="more_defaults", schema="more_defaults.fbs")
|
||||||
|
|
||||||
@@ -432,6 +399,7 @@ flatc(
|
|||||||
)
|
)
|
||||||
flatc(SWIFT_OPTS, schema="optional_scalars.fbs", prefix=swift_prefix)
|
flatc(SWIFT_OPTS, schema="optional_scalars.fbs", prefix=swift_prefix)
|
||||||
flatc(SWIFT_OPTS, schema="vector_has_test.fbs", prefix=swift_prefix)
|
flatc(SWIFT_OPTS, schema="vector_has_test.fbs", prefix=swift_prefix)
|
||||||
|
flatc(SWIFT_OPTS, schema="nan_inf_test.fbs", prefix=swift_prefix)
|
||||||
flatc(
|
flatc(
|
||||||
SWIFT_OPTS + ["--gen-object-api"],
|
SWIFT_OPTS + ["--gen-object-api"],
|
||||||
schema="more_defaults.fbs",
|
schema="more_defaults.fbs",
|
||||||
@@ -455,6 +423,15 @@ flatc(
|
|||||||
cwd=swift_code_gen
|
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 Tests
|
||||||
NIM_OPTS = BASE_OPTS + ["--nim"]
|
NIM_OPTS = BASE_OPTS + ["--nim"]
|
||||||
flatc(NIM_OPTS, schema="monster_test.fbs", include="include_test")
|
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")
|
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 = [
|
COMMON_ARGS = [
|
||||||
"--grpc",
|
"--grpc",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
printf -v year '%(%y)T' -1
|
printf -v year '%(%y)T' -1
|
||||||
printf -v month '%(%m)T' -1
|
printf -v month '%(%-m)T' -1
|
||||||
printf -v day '%(%d)T' -1
|
printf -v day '%(%-d)T' -1
|
||||||
|
|
||||||
version="$year.$month.$day"
|
version="$year.$month.$day"
|
||||||
version_underscore="$year\_$month\_$day"
|
version_underscore="$year\_$month\_$day"
|
||||||
@@ -63,6 +63,11 @@ sed -i \
|
|||||||
-e "s/\(version='\).*/\1$version',/" \
|
-e "s/\(version='\).*/\1$version',/" \
|
||||||
python/setup.py
|
python/setup.py
|
||||||
|
|
||||||
|
echo "Updating rust/flatbuffers/Cargo.toml..."
|
||||||
|
sed -i \
|
||||||
|
"s/^version = \".*\"$/version = \"$version\"/g" \
|
||||||
|
rust/flatbuffers/Cargo.toml
|
||||||
|
|
||||||
echo "Updating FlatBuffers.podspec..."
|
echo "Updating FlatBuffers.podspec..."
|
||||||
sed -i \
|
sed -i \
|
||||||
-e "s/\(s.version\s*= \).*/\1'$version'/" \
|
-e "s/\(s.version\s*= \).*/\1'$version'/" \
|
||||||
|
|||||||
@@ -12,20 +12,44 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import argparse
|
||||||
import platform
|
import platform
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
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
|
# Get the path where this script is located so we can invoke the script from
|
||||||
# any directory and have the paths work correctly.
|
# any directory and have the paths work correctly.
|
||||||
script_path = Path(__file__).parent.resolve()
|
script_path = Path(__file__).parent.resolve()
|
||||||
|
|
||||||
# Get the root path as an absolute path, so all derived paths are absolute.
|
# Get the root path as an absolute path, so all derived paths are absolute.
|
||||||
root_path = script_path.parent.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
|
# Get the location of the flatc executable, reading from the first command line
|
||||||
# argument or defaulting to default names.
|
# 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.
|
# Find and assert flatc compiler is present.
|
||||||
if root_path in flatc_exe.parents:
|
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)
|
assert flatc_path.exists(), "Cannot find the flatc compiler " + str(flatc_path)
|
||||||
|
|
||||||
# Execute the flatc compiler with the specified parameters
|
# 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
|
cmd = [str(flatc_path)] + options
|
||||||
if prefix:
|
if prefix:
|
||||||
cmd += ["-o"] + [prefix]
|
cmd += ["-o"] + [prefix]
|
||||||
if include:
|
if include:
|
||||||
cmd += ["-I"] + [include]
|
cmd += ["-I"] + [include]
|
||||||
if isinstance(schema, Path):
|
cmd += [schema] if isinstance(schema, str) else schema
|
||||||
cmd += [str(schema)]
|
|
||||||
elif isinstance(schema, str):
|
|
||||||
cmd += [schema]
|
|
||||||
else:
|
|
||||||
cmd += schema
|
|
||||||
if data:
|
if data:
|
||||||
cmd += [data] if isinstance(data, str) else 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)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "annotated_binary_text_gen.h"
|
#include "annotated_binary_text_gen.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -277,7 +278,7 @@ static std::string GenerateDocumentation(const BinaryRegion ®ion,
|
|||||||
|
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
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);
|
ss << GenerateTypeString(region);
|
||||||
s += ss.str();
|
s += ss.str();
|
||||||
}
|
}
|
||||||
@@ -292,7 +293,7 @@ static std::string GenerateDocumentation(const BinaryRegion ®ion,
|
|||||||
const std::string value = ToValueString(region, binary, output_config);
|
const std::string value = ToValueString(region, binary, output_config);
|
||||||
|
|
||||||
std::stringstream ss;
|
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);
|
ss << value.substr(0, output_config.max_bytes_per_line);
|
||||||
s += ss.str();
|
s += ss.str();
|
||||||
|
|
||||||
@@ -300,7 +301,7 @@ static std::string GenerateDocumentation(const BinaryRegion ®ion,
|
|||||||
value.substr(std::min(output_config.max_bytes_per_line, value.size()));
|
value.substr(std::min(output_config.max_bytes_per_line, value.size()));
|
||||||
} else {
|
} else {
|
||||||
std::stringstream ss;
|
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);
|
ss << ToValueString(region, binary, output_config);
|
||||||
s += ss.str();
|
s += ss.str();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -470,6 +470,13 @@ class NimBfbsGenerator : public BaseBfbsGenerator {
|
|||||||
std::string DefaultValue(const r::Field *field) const {
|
std::string DefaultValue(const r::Field *field) const {
|
||||||
const r::BaseType base_type = field->type()->base_type();
|
const r::BaseType base_type = field->type()->base_type();
|
||||||
if (IsFloatingPoint(base_type)) {
|
if (IsFloatingPoint(base_type)) {
|
||||||
|
if (field->default_real() != field->default_real()) {
|
||||||
|
return "NaN";
|
||||||
|
} else if (field->default_real() == std::numeric_limits<double>::infinity()) {
|
||||||
|
return "Inf";
|
||||||
|
} else if (field->default_real() == -std::numeric_limits<double>::infinity()) {
|
||||||
|
return "-Inf";
|
||||||
|
}
|
||||||
return NumToString(field->default_real());
|
return NumToString(field->default_real());
|
||||||
}
|
}
|
||||||
if (IsBool(base_type)) {
|
if (IsBool(base_type)) {
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
#include "binary_annotator.h"
|
#include "binary_annotator.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "flatbuffers/reflection.h"
|
#include "flatbuffers/reflection.h"
|
||||||
|
#include "flatbuffers/util.h"
|
||||||
#include "flatbuffers/verifier.h"
|
#include "flatbuffers/verifier.h"
|
||||||
|
|
||||||
namespace flatbuffers {
|
namespace flatbuffers {
|
||||||
@@ -678,7 +680,8 @@ void BinaryAnnotator::BuildTable(const uint64_t table_offset,
|
|||||||
|
|
||||||
if (next_object->is_struct()) {
|
if (next_object->is_struct()) {
|
||||||
// Structs are stored inline.
|
// Structs are stored inline.
|
||||||
BuildStruct(field_offset, regions, next_object);
|
BuildStruct(field_offset, regions, field->name()->c_str(),
|
||||||
|
next_object);
|
||||||
} else {
|
} else {
|
||||||
offset_field_comment.default_value = "(table)";
|
offset_field_comment.default_value = "(table)";
|
||||||
|
|
||||||
@@ -779,6 +782,7 @@ void BinaryAnnotator::BuildTable(const uint64_t table_offset,
|
|||||||
|
|
||||||
uint64_t BinaryAnnotator::BuildStruct(const uint64_t struct_offset,
|
uint64_t BinaryAnnotator::BuildStruct(const uint64_t struct_offset,
|
||||||
std::vector<BinaryRegion> ®ions,
|
std::vector<BinaryRegion> ®ions,
|
||||||
|
const std::string referring_field_name,
|
||||||
const reflection::Object *const object) {
|
const reflection::Object *const object) {
|
||||||
if (!object->is_struct()) { return struct_offset; }
|
if (!object->is_struct()) { return struct_offset; }
|
||||||
uint64_t offset = struct_offset;
|
uint64_t offset = struct_offset;
|
||||||
@@ -793,9 +797,8 @@ uint64_t BinaryAnnotator::BuildStruct(const uint64_t struct_offset,
|
|||||||
|
|
||||||
BinaryRegionComment comment;
|
BinaryRegionComment comment;
|
||||||
comment.type = BinaryRegionCommentType::StructField;
|
comment.type = BinaryRegionCommentType::StructField;
|
||||||
comment.name =
|
comment.name = referring_field_name + "." + field->name()->str();
|
||||||
std::string(object->name()->c_str()) + "." + field->name()->c_str();
|
comment.default_value = "of '" + object->name()->str() + "' (" +
|
||||||
comment.default_value = "(" +
|
|
||||||
std::string(reflection::EnumNameBaseType(
|
std::string(reflection::EnumNameBaseType(
|
||||||
field->type()->base_type())) +
|
field->type()->base_type())) +
|
||||||
")";
|
")";
|
||||||
@@ -820,6 +823,7 @@ uint64_t BinaryAnnotator::BuildStruct(const uint64_t struct_offset,
|
|||||||
} else if (field->type()->base_type() == reflection::BaseType::Obj) {
|
} else if (field->type()->base_type() == reflection::BaseType::Obj) {
|
||||||
// Structs are stored inline, even when nested.
|
// Structs are stored inline, even when nested.
|
||||||
offset = BuildStruct(offset, regions,
|
offset = BuildStruct(offset, regions,
|
||||||
|
referring_field_name + "." + field->name()->str(),
|
||||||
schema_->objects()->Get(field->type()->index()));
|
schema_->objects()->Get(field->type()->index()));
|
||||||
} else if (field->type()->base_type() == reflection::BaseType::Array) {
|
} else if (field->type()->base_type() == reflection::BaseType::Array) {
|
||||||
const bool is_scalar = IsScalar(field->type()->element());
|
const bool is_scalar = IsScalar(field->type()->element());
|
||||||
@@ -832,11 +836,11 @@ uint64_t BinaryAnnotator::BuildStruct(const uint64_t struct_offset,
|
|||||||
if (is_scalar) {
|
if (is_scalar) {
|
||||||
BinaryRegionComment array_comment;
|
BinaryRegionComment array_comment;
|
||||||
array_comment.type = BinaryRegionCommentType::ArrayField;
|
array_comment.type = BinaryRegionCommentType::ArrayField;
|
||||||
array_comment.name = std::string(object->name()->c_str()) + "." +
|
array_comment.name =
|
||||||
field->name()->c_str();
|
referring_field_name + "." + field->name()->str();
|
||||||
array_comment.index = i;
|
array_comment.index = i;
|
||||||
array_comment.default_value =
|
array_comment.default_value =
|
||||||
"(" +
|
"of '" + object->name()->str() + "' (" +
|
||||||
std::string(
|
std::string(
|
||||||
reflection::EnumNameBaseType(field->type()->element())) +
|
reflection::EnumNameBaseType(field->type()->element())) +
|
||||||
")";
|
")";
|
||||||
@@ -868,8 +872,10 @@ uint64_t BinaryAnnotator::BuildStruct(const uint64_t struct_offset,
|
|||||||
// TODO(dbaileychess): This works, but the comments on the fields lose
|
// TODO(dbaileychess): This works, but the comments on the fields lose
|
||||||
// some context. Need to figure a way how to plumb the nested arrays
|
// some context. Need to figure a way how to plumb the nested arrays
|
||||||
// comments together that isn't too confusing.
|
// comments together that isn't too confusing.
|
||||||
offset = BuildStruct(offset, regions,
|
offset =
|
||||||
schema_->objects()->Get(field->type()->index()));
|
BuildStruct(offset, regions,
|
||||||
|
referring_field_name + "." + field->name()->str(),
|
||||||
|
schema_->objects()->Get(field->type()->index()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1017,7 +1023,8 @@ void BinaryAnnotator::BuildVector(const uint64_t vector_offset,
|
|||||||
// Vector of structs
|
// Vector of structs
|
||||||
for (size_t i = 0; i < vector_length.value(); ++i) {
|
for (size_t i = 0; i < vector_length.value(); ++i) {
|
||||||
// Structs are inline to the vector.
|
// 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; }
|
if (next_offset == offset) { break; }
|
||||||
offset = next_offset;
|
offset = next_offset;
|
||||||
}
|
}
|
||||||
@@ -1300,7 +1307,7 @@ std::string BinaryAnnotator::BuildUnion(const uint64_t union_offset,
|
|||||||
// Union of vectors point to a new Binary section
|
// Union of vectors point to a new Binary section
|
||||||
std::vector<BinaryRegion> regions;
|
std::vector<BinaryRegion> regions;
|
||||||
|
|
||||||
BuildStruct(union_offset, regions, object);
|
BuildStruct(union_offset, regions, field->name()->c_str(), object);
|
||||||
|
|
||||||
AddSection(
|
AddSection(
|
||||||
union_offset,
|
union_offset,
|
||||||
|
|||||||
@@ -52,14 +52,14 @@ enum class BinaryRegionType {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
static inline std::string ToHex(T i, size_t width = sizeof(T)) {
|
static inline std::string ToHex(T i, size_t width = sizeof(T)) {
|
||||||
std::stringstream stream;
|
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;
|
<< i;
|
||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Specialized version for uint8_t that don't work well with std::hex.
|
// Specialized version for uint8_t that don't work well with std::hex.
|
||||||
static inline std::string ToHex(uint8_t i) {
|
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 {
|
enum class BinaryRegionStatus {
|
||||||
@@ -273,6 +273,7 @@ class BinaryAnnotator {
|
|||||||
const reflection::Object *table);
|
const reflection::Object *table);
|
||||||
|
|
||||||
uint64_t BuildStruct(uint64_t offset, std::vector<BinaryRegion> ®ions,
|
uint64_t BuildStruct(uint64_t offset, std::vector<BinaryRegion> ®ions,
|
||||||
|
const std::string referring_field_name,
|
||||||
const reflection::Object *structure);
|
const reflection::Object *structure);
|
||||||
|
|
||||||
void BuildString(uint64_t offset, const reflection::Object *table,
|
void BuildString(uint64_t offset, const reflection::Object *table,
|
||||||
|
|||||||
428
src/flatc.cpp
428
src/flatc.cpp
@@ -16,11 +16,16 @@
|
|||||||
|
|
||||||
#include "flatbuffers/flatc.h"
|
#include "flatbuffers/flatc.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <limits>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <memory>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "annotated_binary_text_gen.h"
|
#include "annotated_binary_text_gen.h"
|
||||||
#include "binary_annotator.h"
|
#include "binary_annotator.h"
|
||||||
|
#include "flatbuffers/code_generator.h"
|
||||||
|
#include "flatbuffers/idl.h"
|
||||||
#include "flatbuffers/util.h"
|
#include "flatbuffers/util.h"
|
||||||
|
|
||||||
namespace flatbuffers {
|
namespace flatbuffers {
|
||||||
@@ -30,17 +35,19 @@ static const char *FLATC_VERSION() { return FLATBUFFERS_VERSION(); }
|
|||||||
void FlatCompiler::ParseFile(
|
void FlatCompiler::ParseFile(
|
||||||
flatbuffers::Parser &parser, const std::string &filename,
|
flatbuffers::Parser &parser, const std::string &filename,
|
||||||
const std::string &contents,
|
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);
|
auto local_include_directory = flatbuffers::StripFileName(filename);
|
||||||
include_directories.push_back(local_include_directory.c_str());
|
|
||||||
include_directories.push_back(nullptr);
|
std::vector<const char *> inc_directories;
|
||||||
if (!parser.Parse(contents.c_str(), &include_directories[0],
|
inc_directories.insert(inc_directories.end(), include_directories.begin(),
|
||||||
filename.c_str())) {
|
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);
|
Error(parser.error_, false, false);
|
||||||
}
|
}
|
||||||
if (!parser.error_.empty()) { Warn(parser.error_, false); }
|
if (!parser.error_.empty()) { Warn(parser.error_, false); }
|
||||||
include_directories.pop_back();
|
|
||||||
include_directories.pop_back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlatCompiler::LoadBinarySchema(flatbuffers::Parser &parser,
|
void FlatCompiler::LoadBinarySchema(flatbuffers::Parser &parser,
|
||||||
@@ -61,7 +68,7 @@ void FlatCompiler::Error(const std::string &err, bool usage,
|
|||||||
params_.error_fn(this, err, usage, show_exe_name);
|
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." },
|
{ "o", "", "PATH", "Prefix PATH to all generated files." },
|
||||||
{ "I", "", "PATH", "Search for includes in the specified path." },
|
{ "I", "", "PATH", "Search for includes in the specified path." },
|
||||||
{ "M", "", "", "Print make rules for generated files." },
|
{ "M", "", "", "Print make rules for generated files." },
|
||||||
@@ -86,9 +93,12 @@ const static FlatCOption options[] = {
|
|||||||
{ "", "scoped-enums", "",
|
{ "", "scoped-enums", "",
|
||||||
"Use C++11 style scoped and strongly typed enums. Also implies "
|
"Use C++11 style scoped and strongly typed enums. Also implies "
|
||||||
"--no-prefix." },
|
"--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", "",
|
{ "", "swift-implementation-only", "",
|
||||||
"Adds a @_implementationOnly to swift imports" },
|
"Adds a @_implementationOnly to swift imports" },
|
||||||
{ "", "gen-inclues", "",
|
{ "", "gen-includes", "",
|
||||||
"(deprecated), this is the default behavior. If the original behavior is "
|
"(deprecated), this is the default behavior. If the original behavior is "
|
||||||
"required (no include statements) use --no-includes." },
|
"required (no include statements) use --no-includes." },
|
||||||
{ "", "no-includes", "",
|
{ "", "no-includes", "",
|
||||||
@@ -150,6 +160,8 @@ const static FlatCOption options[] = {
|
|||||||
{ "", "go-import", "IMPORT",
|
{ "", "go-import", "IMPORT",
|
||||||
"Generate the overriding import for flatbuffers in Golang (default is "
|
"Generate the overriding import for flatbuffers in Golang (default is "
|
||||||
"\"github.com/google/flatbuffers/go\")." },
|
"\"github.com/google/flatbuffers/go\")." },
|
||||||
|
{ "", "go-module-name", "",
|
||||||
|
"Prefix local import paths of generated go code with the module name" },
|
||||||
{ "", "raw-binary", "",
|
{ "", "raw-binary", "",
|
||||||
"Allow binaries without file_identifier to be read. This may crash flatc "
|
"Allow binaries without file_identifier to be read. This may crash flatc "
|
||||||
"given a mismatched schema." },
|
"given a mismatched schema." },
|
||||||
@@ -215,14 +227,14 @@ const static FlatCOption options[] = {
|
|||||||
"Allows (de)serialization of JSON text in the Object API. (requires "
|
"Allows (de)serialization of JSON text in the Object API. (requires "
|
||||||
"--gen-object-api)." },
|
"--gen-object-api)." },
|
||||||
{ "", "json-nested-bytes", "",
|
{ "", "json-nested-bytes", "",
|
||||||
"Allow a nested_flatbuffer field to be parsed as a vector of bytes"
|
"Allow a nested_flatbuffer field to be parsed as a vector of bytes "
|
||||||
"in JSON, which is unsafe unless checked by a verifier afterwards." },
|
"in JSON, which is unsafe unless checked by a verifier afterwards." },
|
||||||
{ "", "ts-flat-files", "",
|
{ "", "ts-flat-files", "",
|
||||||
"Only generated one typescript file per .fbs file." },
|
"Only generated one typescript file per .fbs file." },
|
||||||
{ "", "annotate", "SCHEMA",
|
{ "", "annotate", "SCHEMA",
|
||||||
"Annotate the provided BINARY_FILE with the specified SCHEMA file." },
|
"Annotate the provided BINARY_FILE with the specified SCHEMA file." },
|
||||||
{ "", "no-leak-private-annotation", "",
|
{ "", "no-leak-private-annotation", "",
|
||||||
"Prevents multiple type of annotations within a Fbs SCHEMA file."
|
"Prevents multiple type of annotations within a Fbs SCHEMA file. "
|
||||||
"Currently this is required to generate private types in Rust" },
|
"Currently this is required to generate private types in Rust" },
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -293,15 +305,17 @@ static void AppendShortOption(std::stringstream &ss,
|
|||||||
if (!option.long_opt.empty()) { ss << "--" << option.long_opt; }
|
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;
|
std::stringstream ss;
|
||||||
ss << "Usage: " << program_name << " [";
|
ss << "Usage: " << program_name << " [";
|
||||||
|
// TODO(derekbailey): These should be generated from this.generators
|
||||||
for (size_t i = 0; i < params_.num_generators; ++i) {
|
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||||
const Generator &g = params_.generators[i];
|
const Generator &g = params_.generators[i];
|
||||||
AppendShortOption(ss, g.option);
|
AppendShortOption(ss, g.option);
|
||||||
ss << ", ";
|
ss << ", ";
|
||||||
}
|
}
|
||||||
for (const FlatCOption &option : options) {
|
for (const FlatCOption &option : flatc_options) {
|
||||||
AppendShortOption(ss, option);
|
AppendShortOption(ss, option);
|
||||||
ss << ", ";
|
ss << ", ";
|
||||||
}
|
}
|
||||||
@@ -313,17 +327,19 @@ std::string FlatCompiler::GetShortUsageString(const char *program_name) const {
|
|||||||
return ss_textwrap.str();
|
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;
|
std::stringstream ss;
|
||||||
ss << "Usage: " << program_name
|
ss << "Usage: " << program_name
|
||||||
<< " [OPTION]... FILE... [-- BINARY_FILE...]\n";
|
<< " [OPTION]... FILE... [-- BINARY_FILE...]\n";
|
||||||
|
// TODO(derekbailey): These should be generated from this.generators
|
||||||
for (size_t i = 0; i < params_.num_generators; ++i) {
|
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||||
const Generator &g = params_.generators[i];
|
const Generator &g = params_.generators[i];
|
||||||
AppendOption(ss, g.option, 80, 25);
|
AppendOption(ss, g.option, 80, 25);
|
||||||
}
|
}
|
||||||
|
|
||||||
ss << "\n";
|
ss << "\n";
|
||||||
for (const FlatCOption &option : options) {
|
for (const FlatCOption &option : flatc_options) {
|
||||||
AppendOption(ss, option, 80, 25);
|
AppendOption(ss, option, 80, 25);
|
||||||
}
|
}
|
||||||
ss << "\n";
|
ss << "\n";
|
||||||
@@ -334,7 +350,7 @@ std::string FlatCompiler::GetUsageString(const char *program_name) const {
|
|||||||
"after the -- must be binary flatbuffer format files. Output files are "
|
"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 "
|
"named using the base file name of the input, and written to the current "
|
||||||
"directory or the path given by -o. example: " +
|
"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);
|
AppendTextWrappedString(ss, files_description, 80, 0);
|
||||||
ss << "\n";
|
ss << "\n";
|
||||||
return ss.str();
|
return ss.str();
|
||||||
@@ -372,48 +388,34 @@ void FlatCompiler::AnnotateBinaries(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int FlatCompiler::Compile(int argc, const char **argv) {
|
FlatCOptions FlatCompiler::ParseFromCommandLineArguments(int argc,
|
||||||
if (params_.generators == nullptr || params_.num_generators == 0) {
|
const char **argv) {
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc <= 1) { Error("Need to provide at least one argument."); }
|
if (argc <= 1) { Error("Need to provide at least one argument."); }
|
||||||
|
|
||||||
flatbuffers::IDLOptions opts;
|
FlatCOptions options;
|
||||||
std::string output_path;
|
|
||||||
|
|
||||||
bool any_generator = false;
|
// Default all generates to disabled.
|
||||||
bool print_make_rules = false;
|
options.generator_enabled.resize(params_.num_generators, 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;
|
|
||||||
|
|
||||||
const char *program_name = argv[0];
|
options.program_name = std::string(argv[0]);
|
||||||
|
|
||||||
|
IDLOptions &opts = options.opts;
|
||||||
|
|
||||||
for (int argi = 1; argi < argc; argi++) {
|
for (int argi = 1; argi < argc; argi++) {
|
||||||
std::string arg = argv[argi];
|
std::string arg = argv[argi];
|
||||||
if (arg[0] == '-') {
|
if (arg[0] == '-') {
|
||||||
if (filenames.size() && arg[1] != '-')
|
if (options.filenames.size() && arg[1] != '-')
|
||||||
Error("invalid option location: " + arg, true);
|
Error("invalid option location: " + arg, true);
|
||||||
if (arg == "-o") {
|
if (arg == "-o") {
|
||||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
if (++argi >= argc) Error("missing path following: " + arg, true);
|
||||||
output_path = flatbuffers::ConCatPathFileName(
|
options.output_path = flatbuffers::ConCatPathFileName(
|
||||||
flatbuffers::PosixPath(argv[argi]), "");
|
flatbuffers::PosixPath(argv[argi]), "");
|
||||||
} else if (arg == "-I") {
|
} else if (arg == "-I") {
|
||||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
if (++argi >= argc) Error("missing path following: " + arg, true);
|
||||||
include_directories_storage.push_back(
|
options.include_directories_storage.push_back(
|
||||||
flatbuffers::PosixPath(argv[argi]));
|
flatbuffers::PosixPath(argv[argi]));
|
||||||
include_directories.push_back(
|
options.include_directories.push_back(
|
||||||
include_directories_storage.back().c_str());
|
options.include_directories_storage.back().c_str());
|
||||||
} else if (arg == "--bfbs-filenames") {
|
} else if (arg == "--bfbs-filenames") {
|
||||||
if (++argi > argc) Error("missing path following: " + arg, true);
|
if (++argi > argc) Error("missing path following: " + arg, true);
|
||||||
opts.project_root = argv[argi];
|
opts.project_root = argv[argi];
|
||||||
@@ -421,13 +423,13 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
|||||||
Error(arg + " is not a directory: " + opts.project_root);
|
Error(arg + " is not a directory: " + opts.project_root);
|
||||||
} else if (arg == "--conform") {
|
} else if (arg == "--conform") {
|
||||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
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") {
|
} else if (arg == "--conform-includes") {
|
||||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
if (++argi >= argc) Error("missing path following: " + arg, true);
|
||||||
include_directories_storage.push_back(
|
options.include_directories_storage.push_back(
|
||||||
flatbuffers::PosixPath(argv[argi]));
|
flatbuffers::PosixPath(argv[argi]));
|
||||||
conform_include_directories.push_back(
|
options.conform_include_directories.push_back(
|
||||||
include_directories_storage.back().c_str());
|
options.include_directories_storage.back().c_str());
|
||||||
} else if (arg == "--include-prefix") {
|
} else if (arg == "--include-prefix") {
|
||||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
if (++argi >= argc) Error("missing path following: " + arg, true);
|
||||||
opts.include_prefix = flatbuffers::ConCatPathFileName(
|
opts.include_prefix = flatbuffers::ConCatPathFileName(
|
||||||
@@ -446,15 +448,22 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
|||||||
} else if (arg == "--go-import") {
|
} else if (arg == "--go-import") {
|
||||||
if (++argi >= argc) Error("missing golang import" + arg, true);
|
if (++argi >= argc) Error("missing golang import" + arg, true);
|
||||||
opts.go_import = argv[argi];
|
opts.go_import = argv[argi];
|
||||||
|
} else if (arg == "--go-module-name") {
|
||||||
|
if (++argi >= argc) Error("missing golang module name" + arg, true);
|
||||||
|
opts.go_module_name = argv[argi];
|
||||||
} else if (arg == "--defaults-json") {
|
} else if (arg == "--defaults-json") {
|
||||||
opts.output_default_scalars_in_json = true;
|
opts.output_default_scalars_in_json = true;
|
||||||
} else if (arg == "--unknown-json") {
|
} else if (arg == "--unknown-json") {
|
||||||
opts.skip_unexpected_fields_in_json = true;
|
opts.skip_unexpected_fields_in_json = true;
|
||||||
} else if (arg == "--no-prefix") {
|
} else if (arg == "--no-prefix") {
|
||||||
opts.prefixed_enums = false;
|
opts.prefixed_enums = false;
|
||||||
|
} else if (arg == "--cpp-minify-enums") {
|
||||||
|
opts.cpp_minify_enums = true;
|
||||||
} else if (arg == "--scoped-enums") {
|
} else if (arg == "--scoped-enums") {
|
||||||
opts.prefixed_enums = false;
|
opts.prefixed_enums = false;
|
||||||
opts.scoped_enums = true;
|
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") {
|
} else if (arg == "--no-union-value-namespacing") {
|
||||||
opts.union_value_namespacing = false;
|
opts.union_value_namespacing = false;
|
||||||
} else if (arg == "--gen-mutable") {
|
} else if (arg == "--gen-mutable") {
|
||||||
@@ -517,11 +526,11 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
|||||||
opts.one_file = true;
|
opts.one_file = true;
|
||||||
opts.include_dependence_headers = false;
|
opts.include_dependence_headers = false;
|
||||||
} else if (arg == "--raw-binary") {
|
} else if (arg == "--raw-binary") {
|
||||||
raw_binary = true;
|
options.raw_binary = true;
|
||||||
} else if (arg == "--size-prefixed") {
|
} else if (arg == "--size-prefixed") {
|
||||||
opts.size_prefixed = true;
|
opts.size_prefixed = true;
|
||||||
} else if (arg == "--") { // Separator between text and binary inputs.
|
} 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") {
|
} else if (arg == "--proto") {
|
||||||
opts.proto_mode = true;
|
opts.proto_mode = true;
|
||||||
} else if (arg == "--proto-namespace-suffix") {
|
} else if (arg == "--proto-namespace-suffix") {
|
||||||
@@ -530,17 +539,17 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
|||||||
} else if (arg == "--oneof-union") {
|
} else if (arg == "--oneof-union") {
|
||||||
opts.proto_oneof_union = true;
|
opts.proto_oneof_union = true;
|
||||||
} else if (arg == "--schema") {
|
} else if (arg == "--schema") {
|
||||||
schema_binary = true;
|
options.schema_binary = true;
|
||||||
} else if (arg == "-M") {
|
} else if (arg == "-M") {
|
||||||
print_make_rules = true;
|
options.print_make_rules = true;
|
||||||
} else if (arg == "--version") {
|
} else if (arg == "--version") {
|
||||||
printf("flatc version %s\n", FLATC_VERSION());
|
printf("flatc version %s\n", FLATC_VERSION());
|
||||||
exit(0);
|
exit(0);
|
||||||
} else if (arg == "--help" || arg == "-h") {
|
} 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);
|
exit(0);
|
||||||
} else if (arg == "--grpc") {
|
} else if (arg == "--grpc") {
|
||||||
grpc_enabled = true;
|
options.grpc_enabled = true;
|
||||||
} else if (arg == "--bfbs-comments") {
|
} else if (arg == "--bfbs-comments") {
|
||||||
opts.binary_schema_comments = true;
|
opts.binary_schema_comments = true;
|
||||||
} else if (arg == "--bfbs-builtins") {
|
} else if (arg == "--bfbs-builtins") {
|
||||||
@@ -599,41 +608,70 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
|||||||
opts.json_nested_legacy_flatbuffers = true;
|
opts.json_nested_legacy_flatbuffers = true;
|
||||||
} else if (arg == "--ts-flat-files") {
|
} else if (arg == "--ts-flat-files") {
|
||||||
opts.ts_flat_file = true;
|
opts.ts_flat_file = true;
|
||||||
|
} else if (arg == "--ts-no-import-ext") {
|
||||||
|
opts.ts_no_import_ext = true;
|
||||||
} else if (arg == "--no-leak-private-annotation") {
|
} else if (arg == "--no-leak-private-annotation") {
|
||||||
opts.no_leak_private_annotations = true;
|
opts.no_leak_private_annotations = true;
|
||||||
} else if (arg == "--annotate") {
|
} else if (arg == "--annotate") {
|
||||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
if (++argi >= argc) Error("missing path following: " + arg, true);
|
||||||
annotate_schema = flatbuffers::PosixPath(argv[argi]);
|
options.annotate_schema = flatbuffers::PosixPath(argv[argi]);
|
||||||
} else {
|
} else {
|
||||||
for (size_t i = 0; i < params_.num_generators; ++i) {
|
// Look up if the command line argument refers to a code generator.
|
||||||
if (arg == "--" + params_.generators[i].option.long_opt ||
|
auto code_generator_it = code_generators_.find(arg);
|
||||||
arg == "-" + params_.generators[i].option.short_opt) {
|
if (code_generator_it != code_generators_.end()) {
|
||||||
generator_enabled[i] = true;
|
std::shared_ptr<CodeGenerator> code_generator =
|
||||||
any_generator = true;
|
code_generator_it->second;
|
||||||
opts.lang_to_generate |= params_.generators[i].lang;
|
|
||||||
if (params_.generators[i].bfbs_generator) {
|
// TODO(derekbailey): remove in favor of just checking if
|
||||||
opts.binary_schema_comments = true;
|
// generators.empty().
|
||||||
requires_bfbs = true;
|
options.any_generator = true;
|
||||||
}
|
opts.lang_to_generate |= code_generator->Language();
|
||||||
goto found;
|
|
||||||
|
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:;
|
found:;
|
||||||
}
|
}
|
||||||
} else {
|
} 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 (opts.proto_mode) {
|
||||||
if (any_generator)
|
if (options.any_generator)
|
||||||
Error("cannot generate code directly from .proto files", true);
|
Error("cannot generate code directly from .proto files", true);
|
||||||
} else if (!any_generator && conform_to_schema.empty() &&
|
} else if (!options.any_generator && options.conform_to_schema.empty() &&
|
||||||
annotate_schema.empty()) {
|
options.annotate_schema.empty()) {
|
||||||
Error("no options: specify at least one generator.", true);
|
Error("no options: specify at least one generator.", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -642,80 +680,45 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
|||||||
"--cs-gen-json-serializer requires --gen-object-api to be set as "
|
"--cs-gen-json-serializer requires --gen-object-api to be set as "
|
||||||
"well.");
|
"well.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
flatbuffers::Parser FlatCompiler::GetConformParser(
|
||||||
|
const FlatCOptions &options) {
|
||||||
flatbuffers::Parser conform_parser;
|
flatbuffers::Parser conform_parser;
|
||||||
if (!conform_to_schema.empty()) {
|
if (!options.conform_to_schema.empty()) {
|
||||||
std::string contents;
|
std::string contents;
|
||||||
if (!flatbuffers::LoadFile(conform_to_schema.c_str(), true, &contents))
|
if (!flatbuffers::LoadFile(options.conform_to_schema.c_str(), true,
|
||||||
Error("unable to load schema: " + conform_to_schema);
|
&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()) {
|
reflection::SchemaExtension()) {
|
||||||
LoadBinarySchema(conform_parser, conform_to_schema, contents);
|
LoadBinarySchema(conform_parser, options.conform_to_schema, contents);
|
||||||
} else {
|
} else {
|
||||||
ParseFile(conform_parser, conform_to_schema, contents,
|
ParseFile(conform_parser, options.conform_to_schema, contents,
|
||||||
conform_include_directories);
|
options.conform_include_directories);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return conform_parser;
|
||||||
|
}
|
||||||
|
|
||||||
if (!annotate_schema.empty()) {
|
std::unique_ptr<Parser> FlatCompiler::GenerateCode(const FlatCOptions &options,
|
||||||
const std::string ext = flatbuffers::GetExtension(annotate_schema);
|
Parser &conform_parser) {
|
||||||
if (!(ext == reflection::SchemaExtension() || ext == "fbs")) {
|
std::unique_ptr<Parser> parser =
|
||||||
Error("Expected a `.bfbs` or `.fbs` schema, got: " + annotate_schema);
|
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;
|
auto &filename = *file_it;
|
||||||
std::string contents;
|
std::string contents;
|
||||||
if (!flatbuffers::LoadFile(filename.c_str(), true, &contents))
|
if (!flatbuffers::LoadFile(filename.c_str(), true, &contents))
|
||||||
Error("unable to load file: " + filename);
|
Error("unable to load file: " + filename);
|
||||||
|
|
||||||
bool is_binary =
|
bool is_binary = static_cast<size_t>(file_it - options.filenames.begin()) >=
|
||||||
static_cast<size_t>(file_it - filenames.begin()) >= binary_files_from;
|
options.binary_files_from;
|
||||||
auto ext = flatbuffers::GetExtension(filename);
|
auto ext = flatbuffers::GetExtension(filename);
|
||||||
const bool is_schema = ext == "fbs" || ext == "proto";
|
const bool is_schema = ext == "fbs" || ext == "proto";
|
||||||
if (is_schema && opts.project_root.empty()) {
|
if (is_schema && opts.project_root.empty()) {
|
||||||
@@ -727,7 +730,7 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
|||||||
parser->builder_.PushFlatBuffer(
|
parser->builder_.PushFlatBuffer(
|
||||||
reinterpret_cast<const uint8_t *>(contents.c_str()),
|
reinterpret_cast<const uint8_t *>(contents.c_str()),
|
||||||
contents.length());
|
contents.length());
|
||||||
if (!raw_binary) {
|
if (!options.raw_binary) {
|
||||||
// Generally reading binaries that do not correspond to the schema
|
// Generally reading binaries that do not correspond to the schema
|
||||||
// will crash, and sadly there's no way around that when the binary
|
// will crash, and sadly there's no way around that when the binary
|
||||||
// does not contain a file identifier.
|
// does not contain a file identifier.
|
||||||
@@ -757,12 +760,12 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
|||||||
// If we're processing multiple schemas, make sure to start each
|
// If we're processing multiple schemas, make sure to start each
|
||||||
// one from scratch. If it depends on previous schemas it must do
|
// one from scratch. If it depends on previous schemas it must do
|
||||||
// so explicitly using an include.
|
// 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
|
// Try to parse the file contents (binary schema/flexbuffer/textual
|
||||||
// schema)
|
// schema)
|
||||||
if (is_binary_schema) {
|
if (is_binary_schema) {
|
||||||
LoadBinarySchema(*parser.get(), filename, contents);
|
LoadBinarySchema(*parser, filename, contents);
|
||||||
} else if (opts.use_flexbuffers) {
|
} else if (opts.use_flexbuffers) {
|
||||||
if (opts.lang_to_generate == IDLOptions::kJson) {
|
if (opts.lang_to_generate == IDLOptions::kJson) {
|
||||||
auto data = reinterpret_cast<const uint8_t *>(contents.c_str());
|
auto data = reinterpret_cast<const uint8_t *>(contents.c_str());
|
||||||
@@ -773,10 +776,10 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
|||||||
parser->flex_root_ = flexbuffers::GetRoot(data, size);
|
parser->flex_root_ = flexbuffers::GetRoot(data, size);
|
||||||
} else {
|
} else {
|
||||||
parser->flex_builder_.Clear();
|
parser->flex_builder_.Clear();
|
||||||
ParseFile(*parser.get(), filename, contents, include_directories);
|
ParseFile(*parser, filename, contents, options.include_directories);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ParseFile(*parser.get(), filename, contents, include_directories);
|
ParseFile(*parser, filename, contents, options.include_directories);
|
||||||
if (!is_schema && !parser->builder_.GetSize()) {
|
if (!is_schema && !parser->builder_.GetSize()) {
|
||||||
// If a file doesn't end in .fbs, it must be json/binary. Ensure we
|
// 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.
|
// didn't just parse a schema with a different extension.
|
||||||
@@ -785,14 +788,15 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
|||||||
true);
|
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);
|
auto err = parser->ConformTo(conform_parser);
|
||||||
if (!err.empty()) Error("schemas don\'t conform: " + err, false);
|
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();
|
parser->Serialize();
|
||||||
}
|
}
|
||||||
if (schema_binary) {
|
if (options.schema_binary) {
|
||||||
parser->file_extension_ = reflection::SchemaExtension();
|
parser->file_extension_ = reflection::SchemaExtension();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -803,16 +807,67 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
|||||||
// the serialized buffer and length.
|
// the serialized buffer and length.
|
||||||
const uint8_t *bfbs_buffer = nullptr;
|
const uint8_t *bfbs_buffer = nullptr;
|
||||||
int64_t bfbs_length = 0;
|
int64_t bfbs_length = 0;
|
||||||
if (requires_bfbs) {
|
if (options.requires_bfbs) {
|
||||||
parser->Serialize();
|
parser->Serialize();
|
||||||
bfbs_buffer = parser->builder_.GetBufferPointer();
|
bfbs_buffer = parser->builder_.GetBufferPointer();
|
||||||
bfbs_length = parser->builder_.GetSize();
|
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) {
|
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||||
if (generator_enabled[i]) {
|
if (options.generator_enabled[i]) {
|
||||||
if (!print_make_rules) {
|
if (!options.print_make_rules) {
|
||||||
flatbuffers::EnsureDirExists(output_path);
|
flatbuffers::EnsureDirExists(options.output_path);
|
||||||
|
|
||||||
// Prefer bfbs generators if present.
|
// Prefer bfbs generators if present.
|
||||||
if (params_.generators[i].bfbs_generator) {
|
if (params_.generators[i].bfbs_generator) {
|
||||||
@@ -827,7 +882,7 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
|||||||
} else {
|
} else {
|
||||||
if ((!params_.generators[i].schema_only ||
|
if ((!params_.generators[i].schema_only ||
|
||||||
(is_schema || is_binary_schema)) &&
|
(is_schema || is_binary_schema)) &&
|
||||||
!params_.generators[i].generate(*parser.get(), output_path,
|
!params_.generators[i].generate(*parser, options.output_path,
|
||||||
filebase)) {
|
filebase)) {
|
||||||
Error(std::string("Unable to generate ") +
|
Error(std::string("Unable to generate ") +
|
||||||
params_.generators[i].lang_name + " for " + filebase);
|
params_.generators[i].lang_name + " for " + filebase);
|
||||||
@@ -839,16 +894,16 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
|||||||
params_.generators[i].lang_name);
|
params_.generators[i].lang_name);
|
||||||
} else {
|
} else {
|
||||||
std::string make_rule = params_.generators[i].make_rule(
|
std::string make_rule = params_.generators[i].make_rule(
|
||||||
*parser.get(), output_path, filename);
|
*parser, options.output_path, filename);
|
||||||
if (!make_rule.empty())
|
if (!make_rule.empty())
|
||||||
printf("%s\n",
|
printf("%s\n",
|
||||||
flatbuffers::WordWrap(make_rule, 80, " ", " \\").c_str());
|
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 != nullptr) {
|
||||||
if (!params_.generators[i].generateGRPC(*parser.get(), output_path,
|
if (!params_.generators[i].generateGRPC(
|
||||||
filebase)) {
|
*parser, options.output_path, filebase)) {
|
||||||
Error(std::string("Unable to generate GRPC interface for ") +
|
Error(std::string("Unable to generate GRPC interface for ") +
|
||||||
params_.generators[i].lang_name);
|
params_.generators[i].lang_name);
|
||||||
}
|
}
|
||||||
@@ -867,19 +922,84 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
|||||||
Error("root type must be a table");
|
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
|
// We do not want to generate code for the definitions in this file
|
||||||
// in any files coming up next.
|
// in any files coming up next.
|
||||||
parser->MarkGenerated();
|
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
|
// Once all the files have been parsed, run any generators Parsing Completed
|
||||||
// function for final generation.
|
// function for final generation.
|
||||||
for (size_t i = 0; i < params_.num_generators; ++i) {
|
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) {
|
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 " +
|
Error("failed running parsing completed for " +
|
||||||
std::string(params_.generators[i].lang_name));
|
std::string(params_.generators[i].lang_name));
|
||||||
}
|
}
|
||||||
@@ -889,4 +1009,14 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
|||||||
return 0;
|
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
|
} // namespace flatbuffers
|
||||||
|
|||||||
@@ -20,9 +20,12 @@
|
|||||||
#include "bfbs_gen_lua.h"
|
#include "bfbs_gen_lua.h"
|
||||||
#include "bfbs_gen_nim.h"
|
#include "bfbs_gen_nim.h"
|
||||||
#include "flatbuffers/base.h"
|
#include "flatbuffers/base.h"
|
||||||
|
#include "flatbuffers/code_generator.h"
|
||||||
#include "flatbuffers/flatc.h"
|
#include "flatbuffers/flatc.h"
|
||||||
#include "flatbuffers/util.h"
|
#include "flatbuffers/util.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static const char *g_program_name = nullptr;
|
static const char *g_program_name = nullptr;
|
||||||
|
|
||||||
static void Warn(const flatbuffers::FlatCompiler *flatc,
|
static void Warn(const flatbuffers::FlatCompiler *flatc,
|
||||||
@@ -158,5 +161,17 @@ int main(int argc, const char *argv[]) {
|
|||||||
params.error_fn = Error;
|
params.error_fn = Error;
|
||||||
|
|
||||||
flatbuffers::FlatCompiler flatc(params);
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
1158
src/idl_gen_cpp.cpp
1158
src/idl_gen_cpp.cpp
File diff suppressed because it is too large
Load Diff
@@ -655,7 +655,7 @@ class CSharpGenerator : public BaseGenerator {
|
|||||||
// Force compile time error if not using the same version runtime.
|
// Force compile time error if not using the same version runtime.
|
||||||
code += " public static void ValidateVersion() {";
|
code += " public static void ValidateVersion() {";
|
||||||
code += " FlatBufferConstants.";
|
code += " FlatBufferConstants.";
|
||||||
code += "FLATBUFFERS_22_10_26(); ";
|
code += "FLATBUFFERS_23_1_20(); ";
|
||||||
code += "}\n";
|
code += "}\n";
|
||||||
|
|
||||||
// Generate a special accessor for the table that when used as the root
|
// Generate a special accessor for the table that when used as the root
|
||||||
@@ -1425,20 +1425,23 @@ class CSharpGenerator : public BaseGenerator {
|
|||||||
code += "public ";
|
code += "public ";
|
||||||
}
|
}
|
||||||
auto union_name = enum_def.name + "Union";
|
auto union_name = enum_def.name + "Union";
|
||||||
|
auto class_member = std::string("Value");
|
||||||
|
if (class_member == enum_def.name) { class_member += "_"; };
|
||||||
code += "class " + union_name + " {\n";
|
code += "class " + union_name + " {\n";
|
||||||
// Type
|
// Type
|
||||||
code += " public " + enum_def.name + " Type { get; set; }\n";
|
code += " public " + enum_def.name + " Type { get; set; }\n";
|
||||||
// Value
|
// Value
|
||||||
code += " public object Value { get; set; }\n";
|
code += " public object " + class_member + " { get; set; }\n";
|
||||||
code += "\n";
|
code += "\n";
|
||||||
// Constructor
|
// Constructor
|
||||||
code += " public " + union_name + "() {\n";
|
code += " public " + union_name + "() {\n";
|
||||||
code += " this.Type = " + enum_def.name + "." +
|
code += " this.Type = " + enum_def.name + "." +
|
||||||
enum_def.Vals()[0]->name + ";\n";
|
enum_def.Vals()[0]->name + ";\n";
|
||||||
code += " this.Value = null;\n";
|
code += " this." + class_member + " = null;\n";
|
||||||
code += " }\n\n";
|
code += " }\n\n";
|
||||||
// As<T>
|
// As<T>
|
||||||
code += " public T As<T>() where T : class { return this.Value as T; }\n";
|
code += " public T As<T>() where T : class { return this." + class_member +
|
||||||
|
" as T; }\n";
|
||||||
// As, From
|
// As, From
|
||||||
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) {
|
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) {
|
||||||
auto &ev = **it;
|
auto &ev = **it;
|
||||||
@@ -1459,7 +1462,8 @@ class CSharpGenerator : public BaseGenerator {
|
|||||||
code += " " + accessibility + " static " + union_name + " From" +
|
code += " " + accessibility + " static " + union_name + " From" +
|
||||||
ev.name + "(" + type_name + " _" + lower_ev_name +
|
ev.name + "(" + type_name + " _" + lower_ev_name +
|
||||||
") { return new " + union_name + "{ Type = " + Name(enum_def) +
|
") { return new " + union_name + "{ Type = " + Name(enum_def) +
|
||||||
"." + Name(ev) + ", Value = _" + lower_ev_name + " }; }\n";
|
"." + Name(ev) + ", " + class_member + " = _" + lower_ev_name +
|
||||||
|
" }; }\n";
|
||||||
}
|
}
|
||||||
code += "\n";
|
code += "\n";
|
||||||
// Pack()
|
// Pack()
|
||||||
@@ -1521,7 +1525,7 @@ class CSharpGenerator : public BaseGenerator {
|
|||||||
" _o, "
|
" _o, "
|
||||||
"Newtonsoft.Json.JsonSerializer serializer) {\n";
|
"Newtonsoft.Json.JsonSerializer serializer) {\n";
|
||||||
code += " if (_o == null) return;\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 += " }\n";
|
||||||
code +=
|
code +=
|
||||||
" public override object ReadJson(Newtonsoft.Json.JsonReader "
|
" public override object ReadJson(Newtonsoft.Json.JsonReader "
|
||||||
@@ -1558,8 +1562,8 @@ class CSharpGenerator : public BaseGenerator {
|
|||||||
code += " default: break;\n";
|
code += " default: break;\n";
|
||||||
} else {
|
} else {
|
||||||
auto type_name = GenTypeGet_ObjectAPI(ev.union_type, opts);
|
auto type_name = GenTypeGet_ObjectAPI(ev.union_type, opts);
|
||||||
code += " case " + Name(enum_def) + "." + Name(ev) +
|
code += " case " + Name(enum_def) + "." + Name(ev) + ": _o." +
|
||||||
": _o.Value = serializer.Deserialize<" + type_name +
|
class_member + " = serializer.Deserialize<" + type_name +
|
||||||
">(reader); break;\n";
|
">(reader); break;\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1581,6 +1585,8 @@ class CSharpGenerator : public BaseGenerator {
|
|||||||
bool is_vector) const {
|
bool is_vector) const {
|
||||||
auto &code = *code_ptr;
|
auto &code = *code_ptr;
|
||||||
std::string varialbe_name = "_o." + camel_name;
|
std::string varialbe_name = "_o." + camel_name;
|
||||||
|
std::string class_member = "Value";
|
||||||
|
if (class_member == enum_def.name) class_member += "_";
|
||||||
std::string type_suffix = "";
|
std::string type_suffix = "";
|
||||||
std::string func_suffix = "()";
|
std::string func_suffix = "()";
|
||||||
std::string indent = " ";
|
std::string indent = " ";
|
||||||
@@ -1608,7 +1614,8 @@ class CSharpGenerator : public BaseGenerator {
|
|||||||
} else {
|
} else {
|
||||||
code += indent + " case " + NamespacedName(enum_def) + "." + ev.name +
|
code += indent + " case " + NamespacedName(enum_def) + "." + ev.name +
|
||||||
":\n";
|
":\n";
|
||||||
code += indent + " " + varialbe_name + ".Value = this." + camel_name;
|
code += indent + " " + varialbe_name + "." + class_member +
|
||||||
|
" = this." + camel_name;
|
||||||
if (IsString(ev.union_type)) {
|
if (IsString(ev.union_type)) {
|
||||||
code += "AsString" + func_suffix + ";\n";
|
code += "AsString" + func_suffix + ";\n";
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user