2

I am dealing with the protobuf protocol and I encounter the need of decoding messages of unknown fields and types. I know protoc --decode_raw does a good job at that (alas not precise but good enough).

I was thinking about running protoc --decode-raw in a shell and let Python read its content, parsing it as a dictionary, but I figure it is the last resort of implementation.

Is there a Pythonic method of implementing the same functionality?

4

1 回答 1

0

我也有同样的需求,但据我所知,没有官方的 API。有一些内部方法,例如访问msg._unknown_fields空消息和internal.decoder。但这些不是官方 API 的一部分,并且因版本而异。

如果 shell 方法太老套,最好的办法是使用自定义 Python 代码根据文档实现解码。

于 2019-08-11T18:44:00.920 回答