Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/byebyebruce/pbdynamic
通过读取protobuf的file descriptor(protoc --descriptor_set_out)构造动态类型
https://github.com/byebyebruce/pbdynamic
descriptor dynamic dynamicpb proto protobuf protoc
Last synced: about 5 hours ago
JSON representation
通过读取protobuf的file descriptor(protoc --descriptor_set_out)构造动态类型
- Host: GitHub
- URL: https://github.com/byebyebruce/pbdynamic
- Owner: byebyebruce
- Created: 2022-09-30T06:44:34.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2022-09-30T07:02:16.000Z (about 2 years ago)
- Last Synced: 2024-06-21T20:03:26.520Z (5 months ago)
- Topics: descriptor, dynamic, dynamicpb, proto, protobuf, protoc
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pbdynamic
动态解析 protobuf 类型## 原理解释
通过加载pb 描述符文件(protoc --descriptor_set_out=xxx.pb.desc xxx.proto),不需要重新编译xxx.pb.go的情况下动态的构造pb类型,
进而反序列化字节,并打印信息## 快速使用
1. 生成filedesc文件
* [示例](testdata/gen.sh)
```shell
protoc --descriptor_set_out=xxx.pb.desc xxx.proto
```
2. 依赖包
```shell
go get github.com/byebyebruce/pbdynamic@latest
```3. 解析从字节动态反序列化pb并打印
```go
err := pbdynamic.LoadFiles("xxx.pb.desc")
if err != nil {
panic(err)
}// bs 是从其他地方来的pb序列化后的字节
fmt.Println(pbdynamic.String(bs, "mypkg.SomeTypeName"))
```