Python3 GRPC Protobuf 转换为 JSON 或 Python3 对象

Python3 GRPC Protobuf 转换为 JSON 或 Python3 对象

Python3 调用 GRPC 的时候有时候需要将 Protobuf 调用转换为 JSON 或 Python3 对象,这个操作 google.protobuf 库已经帮我们备好了工具

Protobuf -> Python 对象

from google.protobuf.json_format import MessageToJson
jsonObj = MessageToJson(protobuf_obj)

Protobuf -> Python dict

from google.protobuf.json_format import MessageToDict
dict_obj = MessageToDict(org)
posted @   michaelchengjl  阅读(376)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
点击右上角即可分享
微信分享提示