使用 Python,如何获得我的 Google protobuf 消息的二进制序列化? [英] Using Python, how do I get a binary serialization of my Google protobuf message?

查看:28
本文介绍了使用 Python,如何获得我的 Google protobuf 消息的二进制序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 protobuf Python 文档,但就像这暗示的那样,这给了我二进制数据的字符串版本.有没有办法使用 Python 序列化和解析 protobuf 数据的二进制数组?

I see the function SerializeAsString in the protobuf Python documentation, but like this suggests, this gives me a string version of the binary data. Is there a way of serializing and parsing a binary array of protobuf data using Python?

我们有一个 C++ 应用程序,它将 protobuf 消息作为二进制数据存储在一个文件中.我们想使用 Python 读取和写入文件.

We have a C++ application that stores the protobuf messages as binary data in a file. We'd like to read and write to the file using Python.

推荐答案

Python 字符串可以容纳二进制数据,因此 SerializeAsString 返回二进制数据.

Python strings can hold binary data, therefore SerializeAsString returns binary data.

这篇关于使用 Python,如何获得我的 Google protobuf 消息的二进制序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆