关于python:google-protobuf-pb-的三种传输格式

1次阅读

共计 403 个字符,预计需要花费 2 分钟才能阅读完成。

protobuf 的三种传输格局;

  1. protobuf 最省带宽和磁盘的序列化字节流格局

    • Message.SerializeToString() return bytes
    • 反序列化,Message.ParseFromString(bytes)
  2. 通用的 json 格局;

    • google.protobuf.json_format
    • json_format.MessageToJson(Message,**kwargs) 返回 json 后果
    • json_format.Parse(text, Message),text 为 json 格局的 pb
  3. 可视化文本格式;

    • google.protobuf.text_format,print or logging 调用的此办法
    • text_format.MessageToString(Message) 返回 text 格局的后果;
    • text_format.Parse(text, message) 将 text 后果解析到 Pb 的 Message;
正文完
 0