【发布时间】:2021-05-31 15:31:26
【问题描述】:
我正在开发一个以字节格式向我发送 protobuf 消息的应用程序。 .proto文件的结构如下:
syntax = "proto3";
package api;
message RXInfoSimplified {
string ID = 1;
int32 RSSI = 2;
float SNR = 3;
}
message DeviceUplink {
string DevEUI = 1;
int64 ApplicationID = 2;
string MsgType = 3;
int64 Timestamp = 4;
string GatewayID = 5;
int32 RSSI = 6;
float SNR = 7;
float Frequency = 8;
int32 DataRate = 9;
bool ADR = 10;
string Class = 11;
uint32 FCnt = 12;
int32 FPort = 13;
bool Confirm = 14;
bytes Data = 15;
repeated RXInfoSimplified Gateways = 16;
}
我必须以 json 格式或 dict 恢复这些消息。我尝试使用 python pickle 和 marshal 模块,但它不起作用。我想知道是否有其他 python 模块或包可以帮助我解决这个问题。 我正在使用 mqtt 从服务器接收有效负载消息。 我的回调函数:
def on_message(client, userdata, msg):
print(msg.payload)
print(m)
我得到的字节流:
b'\n\x108cf9572000023509\x10\x03\x1a\x06uplink \xcf\xfb\x84\x99\x9c/*\x10b827ebfffebce2d30\xbd\xff\xff\xff\xff\xff\xff\xff\xff\x01=\x00\x00 AEf\x06YDH\x05P\x01Z\x01C`\x84\x0bh\x08z \x02\x05E!"\x00\x00\x11\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd5\x0e\x00\x82\x01"\n\x10b827ebfffebce2d3\x10\xbd\xff\xff\xff\xff\xff\xff\xff\xff\x01\x1d\x00\x00 A'
【问题讨论】:
-
“它不起作用” - 你必须说明 what 不起作用。
-
我刚刚编辑了我的问题
-
我无法将问题中显示的字节流转换为与我的 protobuf 相关的 json。
-
您可能需要考虑使用由协议缓冲区开发人员工作的同一公司维护的搜索站点搜索 protocol buffers python。跨度>
标签: python json protocol-buffers mqtt