protocol-buffers - .proto 文件中的“选项”关键字是什么意思?
问题描述
我有一个示例 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不需要它。至于做什么:来自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 方工具定义。
推荐阅读
- sql-server - 当服务器安装了VS但在非VS服务器上部署构建时未建立连接时,SSIS包测试连接是否有效?
- machine-learning - 书籍成电影 - 数据集建议
- javascript - 如何将html控件ID存储在javascript数组中?
- kubernetes - 即使在 openshift 中指定 cpu 请求后,Pod 创建也会失败
- android - 在 ActionBar 上单击菜单项时打开一个弹出窗口
- javascript - 如何使用google maps JS api从给定的经纬度坐标中找到半径(比如10米)的坐标(纬度和经度)
- blazor - MatBlazor 选择问题
- html - 全屏背景视频不适用于 18:9 移动设备
- java - RapidClipseX、MicroStreamDB:如何将 MicroStream 表分配给 RapidClipseX Grid?
- xpath - 如何在 AEM 的特定组 id 中指定嵌套的“非”操作?