python - Python Implementing protobuf --decode-raw in python
问题描述
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?
解决方案
我也有同样的需求,但据我所知,没有官方的 API。有一些内部方法,例如访问msg._unknown_fields
空消息和internal.decoder。但这些不是官方 API 的一部分,并且因版本而异。
如果 shell 方法太老套,最好的办法是使用自定义 Python 代码根据文档实现解码。
推荐阅读
- python - 如何修复套接字 io setence 中的语法错误
- laravel - 检索从-多到多-连接到-一对多-关系的集合的最佳方法(laravel7)
- python - 动画 matplotlib 的绘图未显示
- reactjs - 在 lodash forOwn 中创建 React 组件
- django - 完整性错误:NOT NULL 约束失败:users_profile.user_id
- ios - 谷歌统一消息平台SDK实现
- json - 如何在反应中从json文件加载嵌套数据
- reactjs - 如何使用 Yup 验证 JSON 对象数组的单个元素
- python-3.x - Python 中递归乐趣的返回值
- python - 即使 USE_TZ = True,Django 时区也会给出错误的结果