找回密码
 立即注册
查看: 191|回复: 0

Proto3: Generating Your Classes - 生成你的类

[复制链接]
发表于 2022-11-22 15:19 | 显示全部楼层 |阅读模式
To generate the Java, Kotlin, Python, C++, Go, Ruby, Objective-C, or C# code you need to work with the message types defined in a .proto file, you need to run the protocol buffer compiler protoc on the .proto. If you haven't installed the compiler, download the package and follow the instructions in the README. For Go, you also need to install a special code generator plugin for the compiler: you can find this and installation instructions in the golang/protobuf repository on GitHub.
为了生成Java、Kotlin、Python、C++、Go、Ruby、Objective-C或 C#代码,你需要使用 .proto 文件中定义的消息类型,使用protocol buffer 编译器protoc编译.proto文件。如果你没有安装编译器 ,下载包然后按照README中的指令操作。对于Go,你还需要为编译器安装特殊的代码生成器插件:你可以在golang/protobufGitHub仓库中找到该插件和安装说明。

The Protocol Compiler is invoked as follows:
Protocol 编译器调用如下:
protoc --proto_path=IMPORT_PATH --cpp_out=DST_DIR --java_out=DST_DIR --python_out=DST_DIR --go_out=DST_DIR --ruby_out=DST_DIR --objc_out=DST_DIR --csharp_out=DST_DIR path/to/file.proto

    IMPORT_PATH specifies a directory in which to look for .proto files when resolving import directives. If omitted, the current directory is used. Multiple import directories can be specified by passing the --proto_path option multiple times; they will be searched in order. -I=_IMPORT_PATH_ can be used as a short form of --proto_path.
    IMPORT_PATH指定在解析import指令时查找.proto文件的目录。如果省略,则使用当前目录。可通过多次传入--proto_path选项来指定多个导入目录;它们将按序查找。-I=_IMPORT_PATH_可以用作--proto_path的简写形式。

  • You can provide one or more output directives:
    你可以提供一个或多个输入指令
      --cpp_out generates C++ code in DST_DIR. See the C++ generated code reference for more.
      --cpp_out在DST_DIR目录下生成C++代码。查看更多信息请参阅C++ 生成代码参考--java_out generates Java code in DST_DIR. See the Java generated code reference for more.--kotlin_out generates additional Kotlin code in DST_DIR. See the Kotlin generated code reference for more.--python_out generates Python code in DST_DIR. See the Python generated code reference for more.--go_out generates Go code in DST_DIR. See the Go generated code reference for more.--ruby_out generates Ruby code in DST_DIR. See the Ruby generated code reference for more.--objc_out generates Objective-C code in DST_DIR. See the Objective-C generated code reference for more.--csharp_out generates C# code in DST_DIR. See the C# generated code reference for more.--php_out generates PHP code in DST_DIR. See the PHP generated code reference for more.

    As an extra convenience, if the DST_DIR ends in .zip or .jar, the compiler will write the output to a single ZIP-format archive file with the given name. .jar outputs will also be given a manifest file as required by the Java JAR specification. Note that if the output archive already exists, it will be overwritten; the compiler is not smart enough to add files to an existing archive.
    作为额外的便利,如果DST_DIR以.zip 或.jar结尾,编译器会将输出写入具有给定名称的单个ZIP格式存档文件中。按照Java JAR规范的要求.jar输出也会提供一个manifest 文件。注意如果输出存档已存在,它会被覆盖;编译器不够智能,无法添加文件到现有归档中。


  • You must provide one or more .proto files as input. Multiple .proto files can be specified at once. Although the files are named relative to the current directory, each file must reside in one of the IMPORT_PATHs so that the compiler can determine its canonical name.
    你必须提过一个或更多.proto文件作为输入。一次可以指定多个.proto文件。尽管文件命名是相对于当前目录的,但每个文件也必须位于IMPORT_PATH之一中,以便编译器决定其规范名称。
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-11-24 18:31 , Processed in 0.088660 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表