nvfuser-cu121-torch25 0.2.25.dev20250201__cp310-cp310-manylinux_2_28_x86_64.whl
Sign up to get free protection for your applications and to get access to all the features.
- nvfuser/_C.cpython-310-x86_64-linux-gnu.so +0 -0
- nvfuser/__init__.py +618 -0
- nvfuser/__init__.pyi +4 -0
- nvfuser/contrib/__init__.py +9 -0
- nvfuser/contrib/nn/__init__.py +13 -0
- nvfuser/contrib/nn/normalization.py +725 -0
- nvfuser/include/nvfuser/alias_analysis.h +116 -0
- nvfuser/include/nvfuser/bfs.h +929 -0
- nvfuser/include/nvfuser/codegen.h +26 -0
- nvfuser/include/nvfuser/compute_at.h +28 -0
- nvfuser/include/nvfuser/compute_at_map.h +394 -0
- nvfuser/include/nvfuser/contiguity.h +351 -0
- nvfuser/include/nvfuser/cuda_utils.h +50 -0
- nvfuser/include/nvfuser/debug.h +50 -0
- nvfuser/include/nvfuser/device_lower/analysis/bank_conflict.h +53 -0
- nvfuser/include/nvfuser/device_lower/analysis/circular_buffer.h +109 -0
- nvfuser/include/nvfuser/device_lower/analysis/device_version.h +65 -0
- nvfuser/include/nvfuser/device_lower/analysis/divisible_split.h +28 -0
- nvfuser/include/nvfuser/device_lower/analysis/fused_reduction.h +36 -0
- nvfuser/include/nvfuser/device_lower/analysis/index_compute.h +322 -0
- nvfuser/include/nvfuser/device_lower/analysis/predicate_elimination.h +71 -0
- nvfuser/include/nvfuser/device_lower/analysis/sync_information.h +47 -0
- nvfuser/include/nvfuser/device_lower/analysis/tensor_memory.h +65 -0
- nvfuser/include/nvfuser/device_lower/analysis/thread_predicate.h +158 -0
- nvfuser/include/nvfuser/device_lower/analysis/tma.h +93 -0
- nvfuser/include/nvfuser/device_lower/analysis/trivial_broadcast.h +75 -0
- nvfuser/include/nvfuser/device_lower/id_model_options.h +135 -0
- nvfuser/include/nvfuser/device_lower/lower2device.h +391 -0
- nvfuser/include/nvfuser/device_lower/pass/alias_memory.h +37 -0
- nvfuser/include/nvfuser/device_lower/pass/allocation.h +32 -0
- nvfuser/include/nvfuser/device_lower/pass/circular_buffer.h +191 -0
- nvfuser/include/nvfuser/device_lower/pass/expr_sort.h +17 -0
- nvfuser/include/nvfuser/device_lower/pass/fusion_simplifier.h +21 -0
- nvfuser/include/nvfuser/device_lower/pass/grid_serialization.h +26 -0
- nvfuser/include/nvfuser/device_lower/pass/index.h +200 -0
- nvfuser/include/nvfuser/device_lower/pass/inline_ptx.h +16 -0
- nvfuser/include/nvfuser/device_lower/pass/insert_syncs.h +39 -0
- nvfuser/include/nvfuser/device_lower/pass/instrument.h +24 -0
- nvfuser/include/nvfuser/device_lower/pass/loop_rotation.h +150 -0
- nvfuser/include/nvfuser/device_lower/pass/loops.h +68 -0
- nvfuser/include/nvfuser/device_lower/pass/magic_zero.h +86 -0
- nvfuser/include/nvfuser/device_lower/pass/misaligned_vectorization.h +118 -0
- nvfuser/include/nvfuser/device_lower/pass/predicate.h +23 -0
- nvfuser/include/nvfuser/device_lower/pass/replace_size.h +24 -0
- nvfuser/include/nvfuser/device_lower/pass/scalar_hoist.h +115 -0
- nvfuser/include/nvfuser/device_lower/pass/unroll.h +98 -0
- nvfuser/include/nvfuser/device_lower/pass/vectorize_welford.h +45 -0
- nvfuser/include/nvfuser/device_lower/pass/warp_reduce.h +23 -0
- nvfuser/include/nvfuser/device_lower/utils.h +382 -0
- nvfuser/include/nvfuser/device_lower/validation.h +74 -0
- nvfuser/include/nvfuser/disjoint_set.h +556 -0
- nvfuser/include/nvfuser/dispatch.h +334 -0
- nvfuser/include/nvfuser/driver_api.h +49 -0
- nvfuser/include/nvfuser/dynamic_transform.h +316 -0
- nvfuser/include/nvfuser/dynamic_type/C++20/type_traits +37 -0
- nvfuser/include/nvfuser/dynamic_type/dynamic_type.h +969 -0
- nvfuser/include/nvfuser/dynamic_type/error.h +24 -0
- nvfuser/include/nvfuser/dynamic_type/type_traits.h +703 -0
- nvfuser/include/nvfuser/evaluator_common.h +295 -0
- nvfuser/include/nvfuser/exceptions.h +283 -0
- nvfuser/include/nvfuser/expr_evaluator.h +125 -0
- nvfuser/include/nvfuser/expr_simplifier.h +218 -0
- nvfuser/include/nvfuser/flatbuffers/allocator.h +68 -0
- nvfuser/include/nvfuser/flatbuffers/array.h +253 -0
- nvfuser/include/nvfuser/flatbuffers/base.h +486 -0
- nvfuser/include/nvfuser/flatbuffers/buffer.h +154 -0
- nvfuser/include/nvfuser/flatbuffers/buffer_ref.h +53 -0
- nvfuser/include/nvfuser/flatbuffers/code_generator.h +80 -0
- nvfuser/include/nvfuser/flatbuffers/code_generators.h +234 -0
- nvfuser/include/nvfuser/flatbuffers/default_allocator.h +64 -0
- nvfuser/include/nvfuser/flatbuffers/detached_buffer.h +114 -0
- nvfuser/include/nvfuser/flatbuffers/flatbuffer_builder.h +1225 -0
- nvfuser/include/nvfuser/flatbuffers/flatbuffers.h +272 -0
- nvfuser/include/nvfuser/flatbuffers/flatc.h +130 -0
- nvfuser/include/nvfuser/flatbuffers/flex_flat_util.h +36 -0
- nvfuser/include/nvfuser/flatbuffers/flexbuffers.h +1889 -0
- nvfuser/include/nvfuser/flatbuffers/grpc.h +300 -0
- nvfuser/include/nvfuser/flatbuffers/hash.h +127 -0
- nvfuser/include/nvfuser/flatbuffers/idl.h +1359 -0
- nvfuser/include/nvfuser/flatbuffers/minireflect.h +420 -0
- nvfuser/include/nvfuser/flatbuffers/reflection.h +522 -0
- nvfuser/include/nvfuser/flatbuffers/reflection_generated.h +1471 -0
- nvfuser/include/nvfuser/flatbuffers/registry.h +128 -0
- nvfuser/include/nvfuser/flatbuffers/stl_emulation.h +513 -0
- nvfuser/include/nvfuser/flatbuffers/string.h +64 -0
- nvfuser/include/nvfuser/flatbuffers/struct.h +53 -0
- nvfuser/include/nvfuser/flatbuffers/table.h +168 -0
- nvfuser/include/nvfuser/flatbuffers/util.h +731 -0
- nvfuser/include/nvfuser/flatbuffers/vector.h +393 -0
- nvfuser/include/nvfuser/flatbuffers/vector_downward.h +273 -0
- nvfuser/include/nvfuser/flatbuffers/verifier.h +317 -0
- nvfuser/include/nvfuser/fusion.h +511 -0
- nvfuser/include/nvfuser/fusion_guard.h +37 -0
- nvfuser/include/nvfuser/fusion_profiler.h +311 -0
- nvfuser/include/nvfuser/fusion_segmenter.h +751 -0
- nvfuser/include/nvfuser/global_allocator.h +27 -0
- nvfuser/include/nvfuser/grouped_reduction.h +47 -0
- nvfuser/include/nvfuser/host_ir/container.h +60 -0
- nvfuser/include/nvfuser/host_ir/executor.h +152 -0
- nvfuser/include/nvfuser/host_ir/host_ir.h +320 -0
- nvfuser/include/nvfuser/host_ir/lower.h +35 -0
- nvfuser/include/nvfuser/id_model/circular_buffer_indexing.h +56 -0
- nvfuser/include/nvfuser/id_model/contiguity.h +166 -0
- nvfuser/include/nvfuser/id_model/id_model.h +359 -0
- nvfuser/include/nvfuser/id_model/id_model_index_compute.h +81 -0
- nvfuser/include/nvfuser/id_model/indexing.h +208 -0
- nvfuser/include/nvfuser/id_model/indexing_traversal.h +72 -0
- nvfuser/include/nvfuser/id_model/indexing_utils.h +62 -0
- nvfuser/include/nvfuser/id_model/loop_promotion.h +180 -0
- nvfuser/include/nvfuser/id_model/predicate_indexing.h +104 -0
- nvfuser/include/nvfuser/id_model/schedule.h +54 -0
- nvfuser/include/nvfuser/id_model/to_string.h +87 -0
- nvfuser/include/nvfuser/id_model/transform_replay.h +58 -0
- nvfuser/include/nvfuser/id_model/utils.h +176 -0
- nvfuser/include/nvfuser/id_model/validation_utils.h +55 -0
- nvfuser/include/nvfuser/index_compute.h +651 -0
- nvfuser/include/nvfuser/instrumentation.h +107 -0
- nvfuser/include/nvfuser/ir/all_nodes.h +14 -0
- nvfuser/include/nvfuser/ir/base_nodes.h +687 -0
- nvfuser/include/nvfuser/ir/builder.h +215 -0
- nvfuser/include/nvfuser/ir/builder_passkey.h +29 -0
- nvfuser/include/nvfuser/ir/cloner.h +185 -0
- nvfuser/include/nvfuser/ir/container.h +226 -0
- nvfuser/include/nvfuser/ir/graphviz.h +119 -0
- nvfuser/include/nvfuser/ir/interface_nodes.h +957 -0
- nvfuser/include/nvfuser/ir/internal_base_nodes.h +744 -0
- nvfuser/include/nvfuser/ir/internal_nodes.h +2792 -0
- nvfuser/include/nvfuser/ir/iostream.h +98 -0
- nvfuser/include/nvfuser/ir/printer.h +57 -0
- nvfuser/include/nvfuser/ir/utils.h +801 -0
- nvfuser/include/nvfuser/iter_visitor.h +661 -0
- nvfuser/include/nvfuser/kernel.h +299 -0
- nvfuser/include/nvfuser/kernel_db/kernel_db.h +109 -0
- nvfuser/include/nvfuser/kernel_db/utils.h +37 -0
- nvfuser/include/nvfuser/kernel_ir.h +1457 -0
- nvfuser/include/nvfuser/kernel_ir_dispatch.h +147 -0
- nvfuser/include/nvfuser/linked_hash_map.h +97 -0
- nvfuser/include/nvfuser/logical_domain_map.h +577 -0
- nvfuser/include/nvfuser/macros.h +23 -0
- nvfuser/include/nvfuser/mma_type.h +257 -0
- nvfuser/include/nvfuser/multidevice/c10d_mock.h +175 -0
- nvfuser/include/nvfuser/multidevice/communication.h +232 -0
- nvfuser/include/nvfuser/multidevice/communicator.h +179 -0
- nvfuser/include/nvfuser/multidevice/device_mesh.h +95 -0
- nvfuser/include/nvfuser/multidevice/executor.h +107 -0
- nvfuser/include/nvfuser/multidevice/multidevice.h +18 -0
- nvfuser/include/nvfuser/multidevice/utils.h +187 -0
- nvfuser/include/nvfuser/non_divisible_split.h +86 -0
- nvfuser/include/nvfuser/opaque_type.h +129 -0
- nvfuser/include/nvfuser/ops/alias.h +192 -0
- nvfuser/include/nvfuser/ops/all_ops.h +13 -0
- nvfuser/include/nvfuser/ops/arith.h +712 -0
- nvfuser/include/nvfuser/ops/composite.h +130 -0
- nvfuser/include/nvfuser/ops/indexing.h +55 -0
- nvfuser/include/nvfuser/ops/normalization.h +263 -0
- nvfuser/include/nvfuser/ops/utils.h +127 -0
- nvfuser/include/nvfuser/options.h +313 -0
- nvfuser/include/nvfuser/parallel_dimension_map.h +95 -0
- nvfuser/include/nvfuser/parallel_type_bitmap.h +365 -0
- nvfuser/include/nvfuser/polymorphic_value.h +432 -0
- nvfuser/include/nvfuser/predicate_compute.h +213 -0
- nvfuser/include/nvfuser/python_frontend/distributed_tensor.h +50 -0
- nvfuser/include/nvfuser/python_frontend/fusion_cache.h +298 -0
- nvfuser/include/nvfuser/python_frontend/fusion_definition.h +372 -0
- nvfuser/include/nvfuser/python_frontend/fusion_record.h +3124 -0
- nvfuser/include/nvfuser/python_frontend/fusion_state.h +143 -0
- nvfuser/include/nvfuser/python_frontend/python_bindings.h +27 -0
- nvfuser/include/nvfuser/python_frontend/segmentation.h +246 -0
- nvfuser/include/nvfuser/python_frontend/translation.h +20 -0
- nvfuser/include/nvfuser/python_frontend/translation_utils.h +308 -0
- nvfuser/include/nvfuser/scheduler/all_schedulers.h +17 -0
- nvfuser/include/nvfuser/scheduler/ampere_multi_matmul.h +206 -0
- nvfuser/include/nvfuser/scheduler/cache_policy_refiner.h +19 -0
- nvfuser/include/nvfuser/scheduler/compile_time_info.h +322 -0
- nvfuser/include/nvfuser/scheduler/debug_utils.h +68 -0
- nvfuser/include/nvfuser/scheduler/expr_eval_sched.h +45 -0
- nvfuser/include/nvfuser/scheduler/heuristic.h +113 -0
- nvfuser/include/nvfuser/scheduler/hopper_multi_matmul.h +204 -0
- nvfuser/include/nvfuser/scheduler/mark_aliases.h +19 -0
- nvfuser/include/nvfuser/scheduler/matmul.h +40 -0
- nvfuser/include/nvfuser/scheduler/matmul_heuristic.h +293 -0
- nvfuser/include/nvfuser/scheduler/matmul_heuristic_plugin.h +65 -0
- nvfuser/include/nvfuser/scheduler/matmul_heuristic_plugin_api.h +99 -0
- nvfuser/include/nvfuser/scheduler/matmul_utils.h +54 -0
- nvfuser/include/nvfuser/scheduler/mma_utils.h +500 -0
- nvfuser/include/nvfuser/scheduler/multi_matmul.h +74 -0
- nvfuser/include/nvfuser/scheduler/no_op.h +48 -0
- nvfuser/include/nvfuser/scheduler/normalization_inner.h +49 -0
- nvfuser/include/nvfuser/scheduler/normalization_inner_outer.h +51 -0
- nvfuser/include/nvfuser/scheduler/normalization_outer.h +48 -0
- nvfuser/include/nvfuser/scheduler/normalization_utils.h +379 -0
- nvfuser/include/nvfuser/scheduler/pointwise.h +183 -0
- nvfuser/include/nvfuser/scheduler/pointwise_heuristic.h +118 -0
- nvfuser/include/nvfuser/scheduler/pointwise_utils.h +24 -0
- nvfuser/include/nvfuser/scheduler/reduction.h +43 -0
- nvfuser/include/nvfuser/scheduler/reduction_heuristic.h +339 -0
- nvfuser/include/nvfuser/scheduler/reduction_utils.h +159 -0
- nvfuser/include/nvfuser/scheduler/registry.h +97 -0
- nvfuser/include/nvfuser/scheduler/registry_utils.h +111 -0
- nvfuser/include/nvfuser/scheduler/resize.h +41 -0
- nvfuser/include/nvfuser/scheduler/resize_heuristic.h +67 -0
- nvfuser/include/nvfuser/scheduler/runtime_info.h +166 -0
- nvfuser/include/nvfuser/scheduler/scheduler_types.h +80 -0
- nvfuser/include/nvfuser/scheduler/transpose.h +114 -0
- nvfuser/include/nvfuser/scheduler/transpose_heuristic.h +164 -0
- nvfuser/include/nvfuser/scheduler/utils.h +771 -0
- nvfuser/include/nvfuser/scheduler/vectorize_helper.h +349 -0
- nvfuser/include/nvfuser/serde/factory.h +55 -0
- nvfuser/include/nvfuser/serde/fusion_cache_generated.h +4319 -0
- nvfuser/include/nvfuser/serde/fusion_record.h +124 -0
- nvfuser/include/nvfuser/serde/polymorphic_value.h +52 -0
- nvfuser/include/nvfuser/serde/utils.h +34 -0
- nvfuser/include/nvfuser/struct.inl +127 -0
- nvfuser/include/nvfuser/swizzle.h +54 -0
- nvfuser/include/nvfuser/sys_utils.h +40 -0
- nvfuser/include/nvfuser/tensor_metadata.h +118 -0
- nvfuser/include/nvfuser/tma.h +124 -0
- nvfuser/include/nvfuser/transform_iter.h +522 -0
- nvfuser/include/nvfuser/transform_replay.h +297 -0
- nvfuser/include/nvfuser/transform_rfactor.h +33 -0
- nvfuser/include/nvfuser/transform_view.h +136 -0
- nvfuser/include/nvfuser/type.h +1125 -0
- nvfuser/include/nvfuser/type_promotion.h +61 -0
- nvfuser/include/nvfuser/utils.h +619 -0
- nvfuser/include/nvfuser/val_graph.h +446 -0
- nvfuser/include/nvfuser/val_graph_visitor.h +259 -0
- nvfuser/include/nvfuser/validator_utils.h +92 -0
- nvfuser/include/nvfuser/vectorization_info.h +31 -0
- nvfuser/include/nvfuser/visibility.h +21 -0
- nvfuser/lib/libnvfuser_codegen.so +0 -0
- nvfuser/nvfuser_version.py +69 -0
- nvfuser/pytorch_utils.py +184 -0
- nvfuser/share/cmake/nvfuser/NvfuserConfig-release.cmake +20 -0
- nvfuser/share/cmake/nvfuser/NvfuserConfig.cmake +106 -0
- nvfuser/utils.py +18 -0
- nvfuser/version.py +1 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/LICENSE +976 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/METADATA +20 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/RECORD +242 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/WHEEL +5 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/top_level.txt +1 -0
- nvfuser_cu121_torch25.libs/libnvToolsExt-847d78f2.so.1.0.0 +0 -0
@@ -0,0 +1,486 @@
|
|
1
|
+
#ifndef FLATBUFFERS_BASE_H_
|
2
|
+
#define FLATBUFFERS_BASE_H_
|
3
|
+
|
4
|
+
// clang-format off
|
5
|
+
|
6
|
+
// If activate should be declared and included first.
|
7
|
+
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \
|
8
|
+
defined(_MSC_VER) && defined(_DEBUG)
|
9
|
+
// The _CRTDBG_MAP_ALLOC inside <crtdbg.h> will replace
|
10
|
+
// calloc/free (etc) to its debug version using #define directives.
|
11
|
+
#define _CRTDBG_MAP_ALLOC
|
12
|
+
#include <stdlib.h>
|
13
|
+
#include <crtdbg.h>
|
14
|
+
// Replace operator new by trace-enabled version.
|
15
|
+
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
|
16
|
+
#define new DEBUG_NEW
|
17
|
+
#endif
|
18
|
+
|
19
|
+
#if !defined(FLATBUFFERS_ASSERT)
|
20
|
+
#include <assert.h>
|
21
|
+
#define FLATBUFFERS_ASSERT assert
|
22
|
+
#elif defined(FLATBUFFERS_ASSERT_INCLUDE)
|
23
|
+
// Include file with forward declaration
|
24
|
+
#include FLATBUFFERS_ASSERT_INCLUDE
|
25
|
+
#endif
|
26
|
+
|
27
|
+
#ifndef ARDUINO
|
28
|
+
#include <cstdint>
|
29
|
+
#endif
|
30
|
+
|
31
|
+
#include <cstddef>
|
32
|
+
#include <cstdlib>
|
33
|
+
#include <cstring>
|
34
|
+
|
35
|
+
#if defined(ARDUINO) && !defined(ARDUINOSTL_M_H) && defined(__AVR__)
|
36
|
+
#include <utility.h>
|
37
|
+
#else
|
38
|
+
#include <utility>
|
39
|
+
#endif
|
40
|
+
|
41
|
+
#include <string>
|
42
|
+
#include <type_traits>
|
43
|
+
#include <vector>
|
44
|
+
#include <set>
|
45
|
+
#include <algorithm>
|
46
|
+
#include <iterator>
|
47
|
+
#include <memory>
|
48
|
+
|
49
|
+
#if defined(__unix__) && !defined(FLATBUFFERS_LOCALE_INDEPENDENT)
|
50
|
+
#include <unistd.h>
|
51
|
+
#endif
|
52
|
+
|
53
|
+
#ifdef __ANDROID__
|
54
|
+
#include <android/api-level.h>
|
55
|
+
#endif
|
56
|
+
|
57
|
+
#if defined(__ICCARM__)
|
58
|
+
#include <intrinsics.h>
|
59
|
+
#endif
|
60
|
+
|
61
|
+
// Note the __clang__ check is needed, because clang presents itself
|
62
|
+
// as an older GNUC compiler (4.2).
|
63
|
+
// Clang 3.3 and later implement all of the ISO C++ 2011 standard.
|
64
|
+
// Clang 3.4 and later implement all of the ISO C++ 2014 standard.
|
65
|
+
// http://clang.llvm.org/cxx_status.html
|
66
|
+
|
67
|
+
// Note the MSVC value '__cplusplus' may be incorrect:
|
68
|
+
// The '__cplusplus' predefined macro in the MSVC stuck at the value 199711L,
|
69
|
+
// indicating (erroneously!) that the compiler conformed to the C++98 Standard.
|
70
|
+
// This value should be correct starting from MSVC2017-15.7-Preview-3.
|
71
|
+
// The '__cplusplus' will be valid only if MSVC2017-15.7-P3 and the `/Zc:__cplusplus` switch is set.
|
72
|
+
// Workaround (for details see MSDN):
|
73
|
+
// Use the _MSC_VER and _MSVC_LANG definition instead of the __cplusplus for compatibility.
|
74
|
+
// The _MSVC_LANG macro reports the Standard version regardless of the '/Zc:__cplusplus' switch.
|
75
|
+
|
76
|
+
#if defined(__GNUC__) && !defined(__clang__)
|
77
|
+
#define FLATBUFFERS_GCC (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
|
78
|
+
#else
|
79
|
+
#define FLATBUFFERS_GCC 0
|
80
|
+
#endif
|
81
|
+
|
82
|
+
#if defined(__clang__)
|
83
|
+
#define FLATBUFFERS_CLANG (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
|
84
|
+
#else
|
85
|
+
#define FLATBUFFERS_CLANG 0
|
86
|
+
#endif
|
87
|
+
|
88
|
+
/// @cond FLATBUFFERS_INTERNAL
|
89
|
+
#if __cplusplus <= 199711L && \
|
90
|
+
(!defined(_MSC_VER) || _MSC_VER < 1600) && \
|
91
|
+
(!defined(__GNUC__) || \
|
92
|
+
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40400))
|
93
|
+
#error A C++11 compatible compiler with support for the auto typing is \
|
94
|
+
required for FlatBuffers.
|
95
|
+
#error __cplusplus _MSC_VER __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__
|
96
|
+
#endif
|
97
|
+
|
98
|
+
#if !defined(__clang__) && \
|
99
|
+
defined(__GNUC__) && \
|
100
|
+
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40600)
|
101
|
+
// Backwards compatibility for g++ 4.4, and 4.5 which don't have the nullptr
|
102
|
+
// and constexpr keywords. Note the __clang__ check is needed, because clang
|
103
|
+
// presents itself as an older GNUC compiler.
|
104
|
+
#ifndef nullptr_t
|
105
|
+
const class nullptr_t {
|
106
|
+
public:
|
107
|
+
template<class T> inline operator T*() const { return 0; }
|
108
|
+
private:
|
109
|
+
void operator&() const;
|
110
|
+
} nullptr = {};
|
111
|
+
#endif
|
112
|
+
#ifndef constexpr
|
113
|
+
#define constexpr const
|
114
|
+
#endif
|
115
|
+
#endif
|
116
|
+
|
117
|
+
// The wire format uses a little endian encoding (since that's efficient for
|
118
|
+
// the common platforms).
|
119
|
+
#if defined(__s390x__)
|
120
|
+
#define FLATBUFFERS_LITTLEENDIAN 0
|
121
|
+
#endif // __s390x__
|
122
|
+
#if !defined(FLATBUFFERS_LITTLEENDIAN)
|
123
|
+
#if defined(__GNUC__) || defined(__clang__) || defined(__ICCARM__)
|
124
|
+
#if (defined(__BIG_ENDIAN__) || \
|
125
|
+
(defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
126
|
+
#define FLATBUFFERS_LITTLEENDIAN 0
|
127
|
+
#else
|
128
|
+
#define FLATBUFFERS_LITTLEENDIAN 1
|
129
|
+
#endif // __BIG_ENDIAN__
|
130
|
+
#elif defined(_MSC_VER)
|
131
|
+
#if defined(_M_PPC)
|
132
|
+
#define FLATBUFFERS_LITTLEENDIAN 0
|
133
|
+
#else
|
134
|
+
#define FLATBUFFERS_LITTLEENDIAN 1
|
135
|
+
#endif
|
136
|
+
#else
|
137
|
+
#error Unable to determine endianness, define FLATBUFFERS_LITTLEENDIAN.
|
138
|
+
#endif
|
139
|
+
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
|
140
|
+
|
141
|
+
#define FLATBUFFERS_VERSION_MAJOR 23
|
142
|
+
#define FLATBUFFERS_VERSION_MINOR 3
|
143
|
+
#define FLATBUFFERS_VERSION_REVISION 3
|
144
|
+
#define FLATBUFFERS_STRING_EXPAND(X) #X
|
145
|
+
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
|
146
|
+
namespace flatbuffers {
|
147
|
+
// Returns version as string "MAJOR.MINOR.REVISION".
|
148
|
+
const char* FLATBUFFERS_VERSION();
|
149
|
+
}
|
150
|
+
|
151
|
+
#if (!defined(_MSC_VER) || _MSC_VER > 1600) && \
|
152
|
+
(!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 407)) || \
|
153
|
+
defined(__clang__)
|
154
|
+
#define FLATBUFFERS_FINAL_CLASS final
|
155
|
+
#define FLATBUFFERS_OVERRIDE override
|
156
|
+
#define FLATBUFFERS_EXPLICIT_CPP11 explicit
|
157
|
+
#define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : flatbuffers::voffset_t
|
158
|
+
#else
|
159
|
+
#define FLATBUFFERS_FINAL_CLASS
|
160
|
+
#define FLATBUFFERS_OVERRIDE
|
161
|
+
#define FLATBUFFERS_EXPLICIT_CPP11
|
162
|
+
#define FLATBUFFERS_VTABLE_UNDERLYING_TYPE
|
163
|
+
#endif
|
164
|
+
|
165
|
+
#if (!defined(_MSC_VER) || _MSC_VER >= 1900) && \
|
166
|
+
(!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)) || \
|
167
|
+
(defined(__cpp_constexpr) && __cpp_constexpr >= 200704)
|
168
|
+
#define FLATBUFFERS_CONSTEXPR constexpr
|
169
|
+
#define FLATBUFFERS_CONSTEXPR_CPP11 constexpr
|
170
|
+
#define FLATBUFFERS_CONSTEXPR_DEFINED
|
171
|
+
#else
|
172
|
+
#define FLATBUFFERS_CONSTEXPR const
|
173
|
+
#define FLATBUFFERS_CONSTEXPR_CPP11
|
174
|
+
#endif
|
175
|
+
|
176
|
+
#if (defined(__cplusplus) && __cplusplus >= 201402L) || \
|
177
|
+
(defined(__cpp_constexpr) && __cpp_constexpr >= 201304)
|
178
|
+
#define FLATBUFFERS_CONSTEXPR_CPP14 FLATBUFFERS_CONSTEXPR_CPP11
|
179
|
+
#else
|
180
|
+
#define FLATBUFFERS_CONSTEXPR_CPP14
|
181
|
+
#endif
|
182
|
+
|
183
|
+
#if (defined(__GXX_EXPERIMENTAL_CXX0X__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)) || \
|
184
|
+
(defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 190023026)) || \
|
185
|
+
defined(__clang__)
|
186
|
+
#define FLATBUFFERS_NOEXCEPT noexcept
|
187
|
+
#else
|
188
|
+
#define FLATBUFFERS_NOEXCEPT
|
189
|
+
#endif
|
190
|
+
|
191
|
+
// NOTE: the FLATBUFFERS_DELETE_FUNC macro may change the access mode to
|
192
|
+
// private, so be sure to put it at the end or reset access mode explicitly.
|
193
|
+
#if (!defined(_MSC_VER) || _MSC_FULL_VER >= 180020827) && \
|
194
|
+
(!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 404)) || \
|
195
|
+
defined(__clang__)
|
196
|
+
#define FLATBUFFERS_DELETE_FUNC(func) func = delete
|
197
|
+
#else
|
198
|
+
#define FLATBUFFERS_DELETE_FUNC(func) private: func
|
199
|
+
#endif
|
200
|
+
|
201
|
+
#if (!defined(_MSC_VER) || _MSC_VER >= 1900) && \
|
202
|
+
(!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)) || \
|
203
|
+
defined(__clang__)
|
204
|
+
#define FLATBUFFERS_DEFAULT_DECLARATION
|
205
|
+
#endif
|
206
|
+
|
207
|
+
// Check if we can use template aliases
|
208
|
+
// Not possible if Microsoft Compiler before 2012
|
209
|
+
// Possible is the language feature __cpp_alias_templates is defined well
|
210
|
+
// Or possible if the C++ std is C+11 or newer
|
211
|
+
#if (defined(_MSC_VER) && _MSC_VER > 1700 /* MSVC2012 */) \
|
212
|
+
|| (defined(__cpp_alias_templates) && __cpp_alias_templates >= 200704) \
|
213
|
+
|| (defined(__cplusplus) && __cplusplus >= 201103L)
|
214
|
+
#define FLATBUFFERS_TEMPLATES_ALIASES
|
215
|
+
#endif
|
216
|
+
|
217
|
+
#ifndef FLATBUFFERS_HAS_STRING_VIEW
|
218
|
+
// Only provide flatbuffers::string_view if __has_include can be used
|
219
|
+
// to detect a header that provides an implementation
|
220
|
+
#if defined(__has_include)
|
221
|
+
// Check for std::string_view (in c++17)
|
222
|
+
#if __has_include(<string_view>) && (__cplusplus >= 201606 || (defined(_HAS_CXX17) && _HAS_CXX17))
|
223
|
+
#include <string_view>
|
224
|
+
namespace flatbuffers {
|
225
|
+
typedef std::string_view string_view;
|
226
|
+
}
|
227
|
+
#define FLATBUFFERS_HAS_STRING_VIEW 1
|
228
|
+
// Check for std::experimental::string_view (in c++14, compiler-dependent)
|
229
|
+
#elif __has_include(<experimental/string_view>) && (__cplusplus >= 201411)
|
230
|
+
#include <experimental/string_view>
|
231
|
+
namespace flatbuffers {
|
232
|
+
typedef std::experimental::string_view string_view;
|
233
|
+
}
|
234
|
+
#define FLATBUFFERS_HAS_STRING_VIEW 1
|
235
|
+
// Check for absl::string_view
|
236
|
+
#elif __has_include("absl/strings/string_view.h") && (__cplusplus >= 201411)
|
237
|
+
#include "absl/strings/string_view.h"
|
238
|
+
namespace flatbuffers {
|
239
|
+
typedef absl::string_view string_view;
|
240
|
+
}
|
241
|
+
#define FLATBUFFERS_HAS_STRING_VIEW 1
|
242
|
+
#endif
|
243
|
+
#endif // __has_include
|
244
|
+
#endif // !FLATBUFFERS_HAS_STRING_VIEW
|
245
|
+
|
246
|
+
#ifndef FLATBUFFERS_GENERAL_HEAP_ALLOC_OK
|
247
|
+
// Allow heap allocations to be used
|
248
|
+
#define FLATBUFFERS_GENERAL_HEAP_ALLOC_OK 1
|
249
|
+
#endif // !FLATBUFFERS_GENERAL_HEAP_ALLOC_OK
|
250
|
+
|
251
|
+
#ifndef FLATBUFFERS_HAS_NEW_STRTOD
|
252
|
+
// Modern (C++11) strtod and strtof functions are available for use.
|
253
|
+
// 1) nan/inf strings as argument of strtod;
|
254
|
+
// 2) hex-float as argument of strtod/strtof.
|
255
|
+
#if (defined(_MSC_VER) && _MSC_VER >= 1900) || \
|
256
|
+
(defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)) || \
|
257
|
+
(defined(__clang__))
|
258
|
+
#define FLATBUFFERS_HAS_NEW_STRTOD 1
|
259
|
+
#endif
|
260
|
+
#endif // !FLATBUFFERS_HAS_NEW_STRTOD
|
261
|
+
|
262
|
+
#ifndef FLATBUFFERS_LOCALE_INDEPENDENT
|
263
|
+
// Enable locale independent functions {strtof_l, strtod_l,strtoll_l,
|
264
|
+
// strtoull_l}.
|
265
|
+
#if (defined(_MSC_VER) && _MSC_VER >= 1800) || \
|
266
|
+
(defined(__ANDROID_API__) && __ANDROID_API__>= 21) || \
|
267
|
+
(defined(_XOPEN_VERSION) && (_XOPEN_VERSION >= 700)) && \
|
268
|
+
(!defined(__Fuchsia__) && !defined(__ANDROID_API__))
|
269
|
+
#define FLATBUFFERS_LOCALE_INDEPENDENT 1
|
270
|
+
#else
|
271
|
+
#define FLATBUFFERS_LOCALE_INDEPENDENT 0
|
272
|
+
#endif
|
273
|
+
#endif // !FLATBUFFERS_LOCALE_INDEPENDENT
|
274
|
+
|
275
|
+
// Suppress Undefined Behavior Sanitizer (recoverable only). Usage:
|
276
|
+
// - __suppress_ubsan__("undefined")
|
277
|
+
// - __suppress_ubsan__("signed-integer-overflow")
|
278
|
+
#if defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7))
|
279
|
+
#define __suppress_ubsan__(type) __attribute__((no_sanitize(type)))
|
280
|
+
#elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)
|
281
|
+
#define __suppress_ubsan__(type) __attribute__((no_sanitize_undefined))
|
282
|
+
#else
|
283
|
+
#define __suppress_ubsan__(type)
|
284
|
+
#endif
|
285
|
+
|
286
|
+
// This is constexpr function used for checking compile-time constants.
|
287
|
+
// Avoid `#pragma warning(disable: 4127) // C4127: expression is constant`.
|
288
|
+
template<typename T> FLATBUFFERS_CONSTEXPR inline bool IsConstTrue(T t) {
|
289
|
+
return !!t;
|
290
|
+
}
|
291
|
+
|
292
|
+
// Enable C++ attribute [[]] if std:c++17 or higher.
|
293
|
+
#if ((__cplusplus >= 201703L) \
|
294
|
+
|| (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
|
295
|
+
// All attributes unknown to an implementation are ignored without causing an error.
|
296
|
+
#define FLATBUFFERS_ATTRIBUTE(attr) attr
|
297
|
+
|
298
|
+
#define FLATBUFFERS_FALLTHROUGH() [[fallthrough]]
|
299
|
+
#else
|
300
|
+
#define FLATBUFFERS_ATTRIBUTE(attr)
|
301
|
+
|
302
|
+
#if FLATBUFFERS_CLANG >= 30800
|
303
|
+
#define FLATBUFFERS_FALLTHROUGH() [[clang::fallthrough]]
|
304
|
+
#elif FLATBUFFERS_GCC >= 70300
|
305
|
+
#define FLATBUFFERS_FALLTHROUGH() [[gnu::fallthrough]]
|
306
|
+
#else
|
307
|
+
#define FLATBUFFERS_FALLTHROUGH()
|
308
|
+
#endif
|
309
|
+
#endif
|
310
|
+
|
311
|
+
/// @endcond
|
312
|
+
|
313
|
+
/// @file
|
314
|
+
namespace flatbuffers {
|
315
|
+
|
316
|
+
/// @cond FLATBUFFERS_INTERNAL
|
317
|
+
// Our default offset / size type, 32bit on purpose on 64bit systems.
|
318
|
+
// Also, using a consistent offset type maintains compatibility of serialized
|
319
|
+
// offset values between 32bit and 64bit systems.
|
320
|
+
typedef uint32_t uoffset_t;
|
321
|
+
|
322
|
+
// Signed offsets for references that can go in both directions.
|
323
|
+
typedef int32_t soffset_t;
|
324
|
+
|
325
|
+
// Offset/index used in v-tables, can be changed to uint8_t in
|
326
|
+
// format forks to save a bit of space if desired.
|
327
|
+
typedef uint16_t voffset_t;
|
328
|
+
|
329
|
+
typedef uintmax_t largest_scalar_t;
|
330
|
+
|
331
|
+
// In 32bits, this evaluates to 2GB - 1
|
332
|
+
#define FLATBUFFERS_MAX_BUFFER_SIZE ((1ULL << (sizeof(::flatbuffers::soffset_t) * 8 - 1)) - 1)
|
333
|
+
|
334
|
+
// The minimum size buffer that can be a valid flatbuffer.
|
335
|
+
// Includes the offset to the root table (uoffset_t), the offset to the vtable
|
336
|
+
// of the root table (soffset_t), the size of the vtable (uint16_t), and the
|
337
|
+
// size of the referring table (uint16_t).
|
338
|
+
#define FLATBUFFERS_MIN_BUFFER_SIZE sizeof(uoffset_t) + sizeof(soffset_t) + \
|
339
|
+
sizeof(uint16_t) + sizeof(uint16_t)
|
340
|
+
|
341
|
+
// We support aligning the contents of buffers up to this size.
|
342
|
+
#ifndef FLATBUFFERS_MAX_ALIGNMENT
|
343
|
+
#define FLATBUFFERS_MAX_ALIGNMENT 32
|
344
|
+
#endif
|
345
|
+
|
346
|
+
/// @brief The length of a FlatBuffer file header.
|
347
|
+
static const size_t kFileIdentifierLength = 4;
|
348
|
+
|
349
|
+
inline bool VerifyAlignmentRequirements(size_t align, size_t min_align = 1) {
|
350
|
+
return (min_align <= align) && (align <= (FLATBUFFERS_MAX_ALIGNMENT)) &&
|
351
|
+
(align & (align - 1)) == 0; // must be power of 2
|
352
|
+
}
|
353
|
+
|
354
|
+
#if defined(_MSC_VER)
|
355
|
+
#pragma warning(disable: 4351) // C4351: new behavior: elements of array ... will be default initialized
|
356
|
+
#pragma warning(push)
|
357
|
+
#pragma warning(disable: 4127) // C4127: conditional expression is constant
|
358
|
+
#endif
|
359
|
+
|
360
|
+
template<typename T> T EndianSwap(T t) {
|
361
|
+
#if defined(_MSC_VER)
|
362
|
+
#define FLATBUFFERS_BYTESWAP16 _byteswap_ushort
|
363
|
+
#define FLATBUFFERS_BYTESWAP32 _byteswap_ulong
|
364
|
+
#define FLATBUFFERS_BYTESWAP64 _byteswap_uint64
|
365
|
+
#elif defined(__ICCARM__)
|
366
|
+
#define FLATBUFFERS_BYTESWAP16 __REV16
|
367
|
+
#define FLATBUFFERS_BYTESWAP32 __REV
|
368
|
+
#define FLATBUFFERS_BYTESWAP64(x) \
|
369
|
+
((__REV(static_cast<uint32_t>(x >> 32U))) | (static_cast<uint64_t>(__REV(static_cast<uint32_t>(x)))) << 32U)
|
370
|
+
#else
|
371
|
+
#if defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ < 408 && !defined(__clang__)
|
372
|
+
// __builtin_bswap16 was missing prior to GCC 4.8.
|
373
|
+
#define FLATBUFFERS_BYTESWAP16(x) \
|
374
|
+
static_cast<uint16_t>(__builtin_bswap32(static_cast<uint32_t>(x) << 16))
|
375
|
+
#else
|
376
|
+
#define FLATBUFFERS_BYTESWAP16 __builtin_bswap16
|
377
|
+
#endif
|
378
|
+
#define FLATBUFFERS_BYTESWAP32 __builtin_bswap32
|
379
|
+
#define FLATBUFFERS_BYTESWAP64 __builtin_bswap64
|
380
|
+
#endif
|
381
|
+
if (sizeof(T) == 1) { // Compile-time if-then's.
|
382
|
+
return t;
|
383
|
+
} else if (sizeof(T) == 2) {
|
384
|
+
union { T t; uint16_t i; } u = { t };
|
385
|
+
u.i = FLATBUFFERS_BYTESWAP16(u.i);
|
386
|
+
return u.t;
|
387
|
+
} else if (sizeof(T) == 4) {
|
388
|
+
union { T t; uint32_t i; } u = { t };
|
389
|
+
u.i = FLATBUFFERS_BYTESWAP32(u.i);
|
390
|
+
return u.t;
|
391
|
+
} else if (sizeof(T) == 8) {
|
392
|
+
union { T t; uint64_t i; } u = { t };
|
393
|
+
u.i = FLATBUFFERS_BYTESWAP64(u.i);
|
394
|
+
return u.t;
|
395
|
+
} else {
|
396
|
+
FLATBUFFERS_ASSERT(0);
|
397
|
+
return t;
|
398
|
+
}
|
399
|
+
}
|
400
|
+
|
401
|
+
#if defined(_MSC_VER)
|
402
|
+
#pragma warning(pop)
|
403
|
+
#endif
|
404
|
+
|
405
|
+
|
406
|
+
template<typename T> T EndianScalar(T t) {
|
407
|
+
#if FLATBUFFERS_LITTLEENDIAN
|
408
|
+
return t;
|
409
|
+
#else
|
410
|
+
return EndianSwap(t);
|
411
|
+
#endif
|
412
|
+
}
|
413
|
+
|
414
|
+
template<typename T>
|
415
|
+
// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
|
416
|
+
__suppress_ubsan__("alignment")
|
417
|
+
T ReadScalar(const void *p) {
|
418
|
+
return EndianScalar(*reinterpret_cast<const T *>(p));
|
419
|
+
}
|
420
|
+
|
421
|
+
// See https://github.com/google/flatbuffers/issues/5950
|
422
|
+
|
423
|
+
#if (FLATBUFFERS_GCC >= 100000) && (FLATBUFFERS_GCC < 110000)
|
424
|
+
#pragma GCC diagnostic push
|
425
|
+
#pragma GCC diagnostic ignored "-Wstringop-overflow"
|
426
|
+
#endif
|
427
|
+
|
428
|
+
template<typename T>
|
429
|
+
// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
|
430
|
+
__suppress_ubsan__("alignment")
|
431
|
+
void WriteScalar(void *p, T t) {
|
432
|
+
*reinterpret_cast<T *>(p) = EndianScalar(t);
|
433
|
+
}
|
434
|
+
|
435
|
+
template<typename T> struct Offset;
|
436
|
+
template<typename T> __suppress_ubsan__("alignment") void WriteScalar(void *p, Offset<T> t) {
|
437
|
+
*reinterpret_cast<uoffset_t *>(p) = EndianScalar(t.o);
|
438
|
+
}
|
439
|
+
|
440
|
+
#if (FLATBUFFERS_GCC >= 100000) && (FLATBUFFERS_GCC < 110000)
|
441
|
+
#pragma GCC diagnostic pop
|
442
|
+
#endif
|
443
|
+
|
444
|
+
// Computes how many bytes you'd have to pad to be able to write an
|
445
|
+
// "scalar_size" scalar if the buffer had grown to "buf_size" (downwards in
|
446
|
+
// memory).
|
447
|
+
__suppress_ubsan__("unsigned-integer-overflow")
|
448
|
+
inline size_t PaddingBytes(size_t buf_size, size_t scalar_size) {
|
449
|
+
return ((~buf_size) + 1) & (scalar_size - 1);
|
450
|
+
}
|
451
|
+
|
452
|
+
// Generic 'operator==' with conditional specialisations.
|
453
|
+
// T e - new value of a scalar field.
|
454
|
+
// T def - default of scalar (is known at compile-time).
|
455
|
+
template<typename T> inline bool IsTheSameAs(T e, T def) { return e == def; }
|
456
|
+
|
457
|
+
#if defined(FLATBUFFERS_NAN_DEFAULTS) && \
|
458
|
+
defined(FLATBUFFERS_HAS_NEW_STRTOD) && (FLATBUFFERS_HAS_NEW_STRTOD > 0)
|
459
|
+
// Like `operator==(e, def)` with weak NaN if T=(float|double).
|
460
|
+
template<typename T> inline bool IsFloatTheSameAs(T e, T def) {
|
461
|
+
return (e == def) || ((def != def) && (e != e));
|
462
|
+
}
|
463
|
+
template<> inline bool IsTheSameAs<float>(float e, float def) {
|
464
|
+
return IsFloatTheSameAs(e, def);
|
465
|
+
}
|
466
|
+
template<> inline bool IsTheSameAs<double>(double e, double def) {
|
467
|
+
return IsFloatTheSameAs(e, def);
|
468
|
+
}
|
469
|
+
#endif
|
470
|
+
|
471
|
+
// Check 'v' is out of closed range [low; high].
|
472
|
+
// Workaround for GCC warning [-Werror=type-limits]:
|
473
|
+
// comparison is always true due to limited range of data type.
|
474
|
+
template<typename T>
|
475
|
+
inline bool IsOutRange(const T &v, const T &low, const T &high) {
|
476
|
+
return (v < low) || (high < v);
|
477
|
+
}
|
478
|
+
|
479
|
+
// Check 'v' is in closed range [low; high].
|
480
|
+
template<typename T>
|
481
|
+
inline bool IsInRange(const T &v, const T &low, const T &high) {
|
482
|
+
return !IsOutRange(v, low, high);
|
483
|
+
}
|
484
|
+
|
485
|
+
} // namespace flatbuffers
|
486
|
+
#endif // FLATBUFFERS_BASE_H_
|
@@ -0,0 +1,154 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2021 Google Inc. All rights reserved.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
#ifndef FLATBUFFERS_BUFFER_H_
|
18
|
+
#define FLATBUFFERS_BUFFER_H_
|
19
|
+
|
20
|
+
#include <algorithm>
|
21
|
+
|
22
|
+
#include "flatbuffers/base.h"
|
23
|
+
|
24
|
+
namespace flatbuffers {
|
25
|
+
|
26
|
+
// Wrapper for uoffset_t to allow safe template specialization.
|
27
|
+
// Value is allowed to be 0 to indicate a null object (see e.g. AddOffset).
|
28
|
+
template<typename T> struct Offset {
|
29
|
+
uoffset_t o;
|
30
|
+
Offset() : o(0) {}
|
31
|
+
Offset(uoffset_t _o) : o(_o) {}
|
32
|
+
Offset<void> Union() const { return Offset<void>(o); }
|
33
|
+
bool IsNull() const { return !o; }
|
34
|
+
};
|
35
|
+
|
36
|
+
inline void EndianCheck() {
|
37
|
+
int endiantest = 1;
|
38
|
+
// If this fails, see FLATBUFFERS_LITTLEENDIAN above.
|
39
|
+
FLATBUFFERS_ASSERT(*reinterpret_cast<char *>(&endiantest) ==
|
40
|
+
FLATBUFFERS_LITTLEENDIAN);
|
41
|
+
(void)endiantest;
|
42
|
+
}
|
43
|
+
|
44
|
+
template<typename T> FLATBUFFERS_CONSTEXPR size_t AlignOf() {
|
45
|
+
// clang-format off
|
46
|
+
#ifdef _MSC_VER
|
47
|
+
return __alignof(T);
|
48
|
+
#else
|
49
|
+
#ifndef alignof
|
50
|
+
return __alignof__(T);
|
51
|
+
#else
|
52
|
+
return alignof(T);
|
53
|
+
#endif
|
54
|
+
#endif
|
55
|
+
// clang-format on
|
56
|
+
}
|
57
|
+
|
58
|
+
// Lexicographically compare two strings (possibly containing nulls), and
|
59
|
+
// return true if the first is less than the second.
|
60
|
+
static inline bool StringLessThan(const char *a_data, uoffset_t a_size,
|
61
|
+
const char *b_data, uoffset_t b_size) {
|
62
|
+
const auto cmp = memcmp(a_data, b_data, (std::min)(a_size, b_size));
|
63
|
+
return cmp == 0 ? a_size < b_size : cmp < 0;
|
64
|
+
}
|
65
|
+
|
66
|
+
// When we read serialized data from memory, in the case of most scalars,
|
67
|
+
// we want to just read T, but in the case of Offset, we want to actually
|
68
|
+
// perform the indirection and return a pointer.
|
69
|
+
// The template specialization below does just that.
|
70
|
+
// It is wrapped in a struct since function templates can't overload on the
|
71
|
+
// return type like this.
|
72
|
+
// The typedef is for the convenience of callers of this function
|
73
|
+
// (avoiding the need for a trailing return decltype)
|
74
|
+
template<typename T> struct IndirectHelper {
|
75
|
+
typedef T return_type;
|
76
|
+
typedef T mutable_return_type;
|
77
|
+
static const size_t element_stride = sizeof(T);
|
78
|
+
static return_type Read(const uint8_t *p, uoffset_t i) {
|
79
|
+
return EndianScalar((reinterpret_cast<const T *>(p))[i]);
|
80
|
+
}
|
81
|
+
static return_type Read(uint8_t *p, uoffset_t i) {
|
82
|
+
return Read(const_cast<const uint8_t *>(p), i);
|
83
|
+
}
|
84
|
+
};
|
85
|
+
template<typename T> struct IndirectHelper<Offset<T>> {
|
86
|
+
typedef const T *return_type;
|
87
|
+
typedef T *mutable_return_type;
|
88
|
+
static const size_t element_stride = sizeof(uoffset_t);
|
89
|
+
static return_type Read(const uint8_t *p, uoffset_t i) {
|
90
|
+
p += i * sizeof(uoffset_t);
|
91
|
+
return reinterpret_cast<return_type>(p + ReadScalar<uoffset_t>(p));
|
92
|
+
}
|
93
|
+
static mutable_return_type Read(uint8_t *p, uoffset_t i) {
|
94
|
+
p += i * sizeof(uoffset_t);
|
95
|
+
return reinterpret_cast<mutable_return_type>(p + ReadScalar<uoffset_t>(p));
|
96
|
+
}
|
97
|
+
};
|
98
|
+
template<typename T> struct IndirectHelper<const T *> {
|
99
|
+
typedef const T *return_type;
|
100
|
+
typedef T *mutable_return_type;
|
101
|
+
static const size_t element_stride = sizeof(T);
|
102
|
+
static return_type Read(const uint8_t *p, uoffset_t i) {
|
103
|
+
return reinterpret_cast<return_type>(p + i * sizeof(T));
|
104
|
+
}
|
105
|
+
static mutable_return_type Read(uint8_t *p, uoffset_t i) {
|
106
|
+
return reinterpret_cast<mutable_return_type>(p + i * sizeof(T));
|
107
|
+
}
|
108
|
+
};
|
109
|
+
|
110
|
+
/// @brief Get a pointer to the file_identifier section of the buffer.
|
111
|
+
/// @return Returns a const char pointer to the start of the file_identifier
|
112
|
+
/// characters in the buffer. The returned char * has length
|
113
|
+
/// 'flatbuffers::FlatBufferBuilder::kFileIdentifierLength'.
|
114
|
+
/// This function is UNDEFINED for FlatBuffers whose schema does not include
|
115
|
+
/// a file_identifier (likely points at padding or the start of a the root
|
116
|
+
/// vtable).
|
117
|
+
inline const char *GetBufferIdentifier(const void *buf,
|
118
|
+
bool size_prefixed = false) {
|
119
|
+
return reinterpret_cast<const char *>(buf) +
|
120
|
+
((size_prefixed) ? 2 * sizeof(uoffset_t) : sizeof(uoffset_t));
|
121
|
+
}
|
122
|
+
|
123
|
+
// Helper to see if the identifier in a buffer has the expected value.
|
124
|
+
inline bool BufferHasIdentifier(const void *buf, const char *identifier,
|
125
|
+
bool size_prefixed = false) {
|
126
|
+
return strncmp(GetBufferIdentifier(buf, size_prefixed), identifier,
|
127
|
+
flatbuffers::kFileIdentifierLength) == 0;
|
128
|
+
}
|
129
|
+
|
130
|
+
/// @cond FLATBUFFERS_INTERNAL
|
131
|
+
// Helpers to get a typed pointer to the root object contained in the buffer.
|
132
|
+
template<typename T> T *GetMutableRoot(void *buf) {
|
133
|
+
EndianCheck();
|
134
|
+
return reinterpret_cast<T *>(
|
135
|
+
reinterpret_cast<uint8_t *>(buf) +
|
136
|
+
EndianScalar(*reinterpret_cast<uoffset_t *>(buf)));
|
137
|
+
}
|
138
|
+
|
139
|
+
template<typename T> T *GetMutableSizePrefixedRoot(void *buf) {
|
140
|
+
return GetMutableRoot<T>(reinterpret_cast<uint8_t *>(buf) +
|
141
|
+
sizeof(uoffset_t));
|
142
|
+
}
|
143
|
+
|
144
|
+
template<typename T> const T *GetRoot(const void *buf) {
|
145
|
+
return GetMutableRoot<T>(const_cast<void *>(buf));
|
146
|
+
}
|
147
|
+
|
148
|
+
template<typename T> const T *GetSizePrefixedRoot(const void *buf) {
|
149
|
+
return GetRoot<T>(reinterpret_cast<const uint8_t *>(buf) + sizeof(uoffset_t));
|
150
|
+
}
|
151
|
+
|
152
|
+
} // namespace flatbuffers
|
153
|
+
|
154
|
+
#endif // FLATBUFFERS_BUFFER_H_
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2021 Google Inc. All rights reserved.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
#ifndef FLATBUFFERS_BUFFER_REF_H_
|
18
|
+
#define FLATBUFFERS_BUFFER_REF_H_
|
19
|
+
|
20
|
+
#include "flatbuffers/base.h"
|
21
|
+
#include "flatbuffers/verifier.h"
|
22
|
+
|
23
|
+
namespace flatbuffers {
|
24
|
+
|
25
|
+
// Convenient way to bundle a buffer and its length, to pass it around
|
26
|
+
// typed by its root.
|
27
|
+
// A BufferRef does not own its buffer.
|
28
|
+
struct BufferRefBase {}; // for std::is_base_of
|
29
|
+
|
30
|
+
template<typename T> struct BufferRef : BufferRefBase {
|
31
|
+
BufferRef() : buf(nullptr), len(0), must_free(false) {}
|
32
|
+
BufferRef(uint8_t *_buf, uoffset_t _len)
|
33
|
+
: buf(_buf), len(_len), must_free(false) {}
|
34
|
+
|
35
|
+
~BufferRef() {
|
36
|
+
if (must_free) free(buf);
|
37
|
+
}
|
38
|
+
|
39
|
+
const T *GetRoot() const { return flatbuffers::GetRoot<T>(buf); }
|
40
|
+
|
41
|
+
bool Verify() {
|
42
|
+
Verifier verifier(buf, len);
|
43
|
+
return verifier.VerifyBuffer<T>(nullptr);
|
44
|
+
}
|
45
|
+
|
46
|
+
uint8_t *buf;
|
47
|
+
uoffset_t len;
|
48
|
+
bool must_free;
|
49
|
+
};
|
50
|
+
|
51
|
+
} // namespace flatbuffers
|
52
|
+
|
53
|
+
#endif // FLATBUFFERS_BUFFER_REF_H_
|