处理协议插件中的自定义选项
Handling Custom options within a protoc plugin
我正在尝试开发一个插件,以便自动生成特定于我的应用程序的代码。虽然一个可能更简单的策略是让我的代码使用c++插件生成的文件,但我正在尝试从头开始编写插件。
因此,正如我在文件中所解释的,我已经添加到我的包中
import "google/protobuf/descriptor.proto";
extend google.protobuf.FieldOptions {
optional int32 testext = 50000;
}
...
message replyT {
enum ackT {
ok = 0;
failed = 1;
}
required ackT ack = 1 [ (testext) = 42 ];
}
现在的问题是如何访问"testext选项"?
我已经能够使用转储50000 42(分机号和分配的值)
class TestGenerator: public CodeGenerator {
int i;
public:
TestGenerator(const string& name) {};
virtual ~TestGenerator() {};
virtual bool Generate(const FileDescriptor* file,
const string& parameter,
GeneratorContext* context,
string* error) const
{
........................
std::cerr <<"tt"<<file->message_type(i)->field(j)->options().DebugString()<<std::endl;
.................
假设(i和j是正确的)
但除此之外,在研究了文档后,我还无法测试字段是否启用了扩展testext(甚至使用50000)和分配的值。
语言指南建议但是GetExtension方法使用了一个只在*.pb.h内部生成的类型,所以我不能在生成器中使用它。
string value = MyMessage::descriptor()->options().GetExtension(my_option);
有线索吗?
您必须为定义自定义选项的文件运行C++生成器。之后,您可以使用您已经理解的普通GetExtension()
语法。
相关文章:
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- C++自定义比较函数
- 如何比较自定义类的std::变体
- std::设置自定义比较器
- 如何正确实现和访问运算符的各种自定义枚举器
- 用于自定义间距的 .clang 格式选项
- 如何在Boost::program_options配置文件中为非字符串的自定义选项值类型处理空格
- C++,当函子不是一个选项时,我如何编写带有自定义函数调用的模板化 RAII 包装器?
- 如何在"数据链接属性"对话框中自定义"连接"选项卡?
- QTcp服务器:使用自定义选项绑定套接字
- 继承自定义选项卡栏和调整大小事件的实现
- 提升程序选项:自定义验证器是否需要重载运算符>>?
- 使用提升程序选项通过配置文件/命令行解析自定义对象
- 处理协议插件中的自定义选项
- 将自定义类型与提升计划选项结合使用
- 文件属性对话框中的自定义选项卡
- 使用带有自定义对齐分配器实现的最新g++,使用SSE和-O3选项编译时出现非法指令(核心转储)
- Qt:在按钮点击上添加自定义新选项卡
- c++自定义UI工具包——跨平台抽象层的选项