【问题标题】:What does 'option' keyword in a .proto file means?.proto 文件中的“选项”关键字是什么意思?
【发布时间】:2020-07-20 11:14:05
【问题描述】:

我有一个示例 helloworld.proto 文件并使用 Python。我没有得到这个选项关键字在编译阶段必须做什么?

syntax = "proto3";
package services.helloworld;

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

【问题讨论】:

    标签: protocol-buffers grpc grpc-python


    【解决方案1】:

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

    
      // 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 通常是存在哪些内置选项(以及它们的作用)的最佳来源,但是自定义选项可以由 3rd 方工具定义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-14
      • 2010-10-29
      • 2011-10-28
      • 1970-01-01
      相关资源
      最近更新 更多