VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
schema_plugin_interface.h
浏览该文件的文档.
1/*
2 * Copyright (C) 2026 by Thun Lu. All rights reserved.
3 * Author: Thun Lu <thun.lu@zohomail.cn>
4 * Repo: https://github.com/thun-res/vlink
5 * _ __ __ _ __
6 * | | / / / / (_) ____ / /__
7 * | | / / / / / / / __ \ / //_/
8 * | |/ / / /___ / / / / / / / ,<
9 * |___/ /_____/ /_/ /_/ /_/ /_/|_|
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 */
23
24/**
25 * @file schema_plugin_interface.h
26 * @brief Runtime schema plugin interface for Protobuf and FlatBuffers metadata loading.
27 *
28 * @details
29 * @c SchemaPluginInterface provides a unified runtime schema registry for
30 * Protobuf and FlatBuffers. It keeps explicit Protobuf-only reflection hooks
31 * used by @c cli/eproto and the webviz converters, and adds generic schema
32 * listing plus FlatBuffers parser creation so the same plugin
33 * can serve:
34 *
35 * 1. Protobuf @c FileDescriptorSet blobs.
36 * 2. FlatBuffers BFBS blobs.
37 * 3. Mixed schema registries for MCAP/bag embedding.
38 * 4. Reusable FlatBuffers parsers for @c cli/efbs and other runtime tooling.
39 *
40 */
41
42#pragma once
43
44#include <string>
45#include <vector>
46
47#include "../base/plugin.h"
48#include "../impl/types.h"
49
50namespace vlink {
51
52/**
53 * @class SchemaPluginInterface
54 * @brief Abstract interface for runtime schema lookup and dynamic object creation.
55 *
56 * @details
57 * Loaded as a dynamic plugin via @c Plugin::load<SchemaPluginInterface>().
58 * @c SchemaPluginManager provides a convenient singleton accessor.
59 *
60 * The interface intentionally exposes both generic schema APIs and encoding-specific
61 * runtime hooks:
62 * - Generic APIs such as @c search_schema() and @c get_all_schemas() are used by
63 * bag/database/MCAP embedding logic.
64 * - Protobuf-specific hooks are consumed by @c cli/eproto and webviz protobuf decoders.
65 * - FlatBuffers-specific hooks are consumed by @c cli/efbs and runtime BFBS-based decoders.
66 */
69
70 protected:
72
73 virtual ~SchemaPluginInterface() = default;
74
75 public:
76 /**
77 * @brief Opaque pointer type for a @c google::protobuf::Descriptor.
78 *
79 * @details
80 * Callers that know the concrete plugin implementation may cast this to
81 * @c google::protobuf::Descriptor* directly.
82 */
83 using ProtobufDescriptorPtr = void*;
84
85 /**
86 * @brief Opaque pointer type for a @c google::protobuf::Message instance.
87 *
88 * @details
89 * Callers may cast this to @c google::protobuf::Message* for dynamic access.
90 */
91 using ProtobufMessagePtr = void*;
92
93 /**
94 * @brief Opaque pointer type for a FlatBuffers @c reflection::Schema instance.
95 *
96 * @details
97 * Callers that include FlatBuffers reflection headers may cast this to
98 * @c reflection::Schema* directly.
99 */
100 using FlatbuffersSchemaPtr = void*;
101
102 /**
103 * @brief Opaque pointer type for a runtime FlatBuffers @c Parser instance.
104 *
105 * @details
106 * Callers may cast this to @c flatbuffers::Parser* when FlatBuffers headers are available.
107 */
108 using FlatbuffersParserPtr = void*;
109
110 /**
111 * @struct VersionInfo
112 * @brief Plugin version and build metadata.
113 */
114 struct VersionInfo final {
115 std::string name; ///< Plugin display name.
116 std::string version; ///< Semantic version string.
117 std::string timestamp; ///< Build timestamp.
118 std::string tag; ///< Source control tag.
119 std::string commit_id; ///< Source control commit hash.
120 };
121
122 /**
123 * @brief Returns version and build metadata for this plugin.
124 *
125 * @return @c VersionInfo with name, version, timestamp, tag, and commit ID.
126 */
127 [[nodiscard]] virtual VersionInfo get_version_info() const = 0;
128
129 /**
130 * @brief Finds one schema constrained by schema family.
131 *
132 * @details
133 * Callers that already know the expected schema family (for example derived from
134 * compile-time traits or discovery metadata) should supply @p schema_type to
135 * skip family-agnostic probing. Passing @c SchemaType::kUnknown still performs
136 * a best-effort lookup across every registered family.
137 *
138 * @param name Serialization type / message type name.
139 * @param schema_type Coarse schema family hint, or @c SchemaType::kUnknown for
140 * family-agnostic lookup.
141 * @return Matching @c SchemaData, or an empty schema when not found.
142 */
143 [[nodiscard]] virtual SchemaData search_schema(const std::string& name,
144 SchemaType schema_type = SchemaType::kUnknown) = 0;
145
146 /**
147 * @brief Returns all imported or cached schemas filtered by schema family.
148 *
149 * @param schema_type Schema family to filter on; @c SchemaType::kUnknown returns
150 * every cached schema.
151 * @return List of schemas belonging to @p schema_type.
152 */
153 [[nodiscard]] virtual std::vector<SchemaData> get_all_schemas(SchemaType schema_type = SchemaType::kUnknown) = 0;
154
155 /**
156 * @brief Looks up a Protobuf descriptor by fully-qualified message name.
157 *
158 * @details
159 * For non-Protobuf types this returns @c nullptr.
160 *
161 * @param name Fully-qualified Protobuf message type name.
162 * @return Opaque @c Descriptor pointer, or @c nullptr if not found.
163 */
164 [[nodiscard]] virtual ProtobufDescriptorPtr search_protobuf_descriptor(const std::string& name) = 0;
165
166 /**
167 * @brief Creates a Protobuf dynamic message prototype for the named type.
168 *
169 * @details
170 * For non-Protobuf types this returns @c nullptr.
171 *
172 * @param name Fully-qualified Protobuf message type name.
173 * @return Opaque @c Message pointer, or @c nullptr if not found.
174 */
175 [[nodiscard]] virtual ProtobufMessagePtr create_protobuf_message(const std::string& name) = 0;
176
177 /**
178 * @brief Looks up a FlatBuffers binary-schema reflection handle by type name.
179 *
180 * @details
181 * The returned handle points at the BFBS-backed @c reflection::Schema for the
182 * requested root type. For non-FlatBuffers types this returns @c nullptr.
183 *
184 * @param name Fully-qualified FlatBuffers root type name.
185 * @return Opaque BFBS reflection schema handle, or @c nullptr if not found.
186 */
187 [[nodiscard]] virtual FlatbuffersSchemaPtr search_flatbuffers_schema(const std::string& name) = 0;
188
189 /**
190 * @brief Creates a FlatBuffers parser preloaded with the named schema.
191 *
192 * @details
193 * The returned parser is backed by the plugin lifetime and already contains
194 * the BFBS schema plus the requested root type. For non-FlatBuffers types
195 * this returns @c nullptr.
196 *
197 * @param name Fully-qualified FlatBuffers root type name.
198 * @return Opaque runtime parser handle, or @c nullptr if not found.
199 */
200 [[nodiscard]] virtual FlatbuffersParserPtr create_flatbuffers_parser(const std::string& name) = 0;
201
202 private:
204};
205
206} // namespace vlink
#define VLINK_DISALLOW_COPY_AND_ASSIGN(classname)
Deletes the copy constructor and copy-assignment operator of classname.
定义 macros.h:184
Type-safe dynamic plugin loader with version checking and lifecycle management.
#define VLINK_PLUGIN_REGISTER(InterfaceType)
Macro to register a plugin, automatically deriving its ID from the interface type name.
定义 plugin.h:343
Core type definitions shared across all VLink node implementations.