protoc
约 2 分钟阅读
| flag | for |
|---|---|
-I,--proto_path <PATH> | 默认当前目录, --descriptor_set_in |
--encode <MESSAGE_TYPE> | text -> proto |
| --deterministic_output | 当 --encode 确保 map 顺序固定 |
--decode <MESSAGE_TYPE> | proto -> text |
| --decode_raw | proto -> tag,value - 不需要 proto |
--descriptor_set_in <FILES> | FileDescriptorSet 列表 descriptor.proto |
-o,--descriptor_set_out <FILE> | FileDescriptorSet |
| --include_imports | 当 --descriptor_set_out 包含依赖 |
| --include_source_info | 当 --descriptor_set_out 保留 SourceCodeInfo |
| --dependency_out=FILE | 输出 make 依赖 |
| --error_format=FORMAT | gcc, msvs |
| --fatal_warnings | warnings -> fatal |
| --print_free_field_numbers | |
| --plugin=EXECUTABLE | 默认 PATH, 可以是 NAME=PATH |
@<filename> | 从文件读取配置 |
- 插件
<plugin>_out- 输出目录 - 例如.:.,.:./gen/out<plugin>_opt- 参数
- plugin
- cpp
- csharp
- java
- js
- kotlin
- objc
- php protobuf.dev/reference/php/php-generated
- php_namespace
- php_metadata_namespace
- php_class_prefix
- python
- ruby
- descriptor_set
- 预生成 descriptor,之后则不需要 proto 源文件
Plugins
protoc-gen-<plugin>- protoc-gen-validate笔记protoc-gen-validateenvoyproxy/protoc-gen-validate · 提供校验能力 · 支持 go,java,cc打开:/notes/service/api/protobuf/protoc-gen-validate 校验 message
- go,java,cc
- protoc-gen-cGitHubprotobuf-c/protobuf-cprotocolbuffers/protobuf · Protocol Buffers - Google's data interchange format · 包含实现: C++, Java, Python, Objective-C, C#, Ruby, PHP笔记:protobuf
- Golang
- protoc-gen-goGitHubprotocolbuffers/protobuf-goprotocolbuffers/protobuf-go · 2020-03-02 A new Go API for Protocol Buffers · APIv1 github.com/golang/protobuf · github.com/golang/[email protected] 使用 APIv2 实现笔记:Protobuf Go
- protoc-gen-go-jsonGitHubmitchellh/protoc-gen-go-json Go JSON Marshal/Unmarshal
- protoc-gen-go-vtproto
- protoc-gen-gotag
- gogo/protobufGitHubgogo/protobuf| flag | for | · | -I,--protopath | 默认当前目录, --descriptorsetin | · | --encode | text -> proto | · | --deterministicoutput | 当 确保 map 顺序固定 |笔记:protoc
- APIv2 发布后不再维护
- protoc-gen-{gofast,combo,gogo,gogofast,gogofaster,gogoslic,gogotypes,gostring}
- Document
- protoc-gen-slate
- protoc-gen-swagger
- protoc-gen-docGitHubpseudomuto/protoc-gen-doc
- Schema
- protoc-gen-jsonschemaGitHubchrusty/protoc-gen-jsonschema
- protoc-gen-bq-schemaGitHubGoogleCloudPlatform/protoc-gen-bq-schema
- pb to BigQuery schema
Descriptor
- proto 解析过后的结构
- DescriptorProto - Message
- field FieldDescriptorProto
- extension
- nested_type - DescriptorProto
- enum_type - EnumDescriptorProto
- oneof - OneofDescriptorProto
- options - MessageOptions
Write Plugins
- 插件协议 protocolbuffers/protobuf/src/google/protobuf/compiler/plugin.protoGitHub 文件protocolbuffers/protobuf/src/google/protobuf/compiler/plugin.proto
- 通过 stdio 交互
- lyft/protoc-gen-starGitHublyft/protoc-gen-star
- 辅助实现插件
- protoc-gen-debugGitHub 文件lyft/protoc-gen-star/protoc-gen-debug
- 生成 bin,用于测试插件
- danielgtaylor/python-betterprotoGitHubdanielgtaylor/python-betterproto
- Python 3.6+ code generator & library for Protobuf 3 and async gRPC
- json-to-proto
关联信息
反向链接、本文链接的其他页面和外部资料。
反向链接
- protobuf笔记 · protoc
protocolbuffers/protobuf · Protocol Buffers - Google's data interchange format · 包含实现: C++, Java, Python, Objective-C, C#, Ruby, PHP
站内链接
- protoc-gen-validate笔记 · protoc-gen-validate
envoyproxy/protoc-gen-validate · 提供校验能力 · 支持 go,java,cc
参考资料
GitHub11 条
- chrusty/protoc-gen-jsonschemagithub.com/chrusty/protoc-gen-jsonschema
- danielgtaylor/python-betterprotogithub.com/danielgtaylor/python-betterproto
- gogo/protobufgithub.com/gogo/protobuf
- GoogleCloudPlatform/protoc-gen-bq-schemagithub.com/GoogleCloudPlatform/protoc-gen-bq-schema
- lyft/protoc-gen-stargithub.com/lyft/protoc-gen-star
- lyft/protoc-gen-star/protoc-gen-debuggithub.com/lyft/protoc-gen-star/tree/master/protoc-gen-debug
- mitchellh/protoc-gen-go-jsongithub.com/mitchellh/protoc-gen-go-json
- protobuf-c/protobuf-cgithub.com/protobuf-c/protobuf-c
- protocolbuffers/protobuf-gogithub.com/protocolbuffers/protobuf-go
- protocolbuffers/protobuf/src/google/protobuf/compiler/plugin.protogithub.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/compiler/plugin.proto
- pseudomuto/protoc-gen-docgithub.com/pseudomuto/protoc-gen-doc
其他外链2 条
- json-to-proto.github.iojson-to-proto.github.io/
- protobuf.dev/reference/php/php-generatedprotobuf.dev/reference/php/php-generated