.proto 文件中'option'关键字是什么意思?



我有一个示例helloworld.proto文件,并使用Python。我不明白这个选项关键字在编译阶段要做什么?

syntax = "proto3";
package services.helloworld;
option go_package = "github.com/xyz/api/go/services/helloworld";

对于python用户?可能不多。选项被解析为DSL对象模型(FileDescriptorSet(,并且可以由处理模式的任何工具使用。"go"处理器可能会使用该选项来确定包/命名空间等。另一方面,python处理器可能一点也不感兴趣。没有"py"等价物,所以我认为python不需要它。至于做什么:来自描述符。主题:


// Sets the Go package where structs generated from this .proto will be
// placed. If omitted, the Go package will be derived from the following:
//   - The basename of the package import path, if provided.
//   - Otherwise, the package statement in the .proto file, if present.
//   - Otherwise, the basename of the .proto file, without extension.
optional string go_package = 11;

不同的选择会做不同的事情;descriptor.proto通常是内置选项的最佳来源(以及它们的功能(,但是自定义选项可以由第三方工具定义。

最新更新