我想在python
中编码一个protopuf,并通过redis将其发送到java
应用程序,在那里我decode
它。
Atm我可以在java
应用程序中打印数据,并且值是正确的。但每次我收到数据时都会出现以下异常:
InvalidProtocolBufferException: Protocol message end-group tag did not match expected tag
我也试过绝地武士,但那里的数据是错误的。也尝试在没有python的bytearray强制转换的情况下发送它,但是我在这里得到了相同的错误。在
有人对这个问题有什么想法吗?在
python
侧的代码:
Java
侧的代码:
import com.google.protobuf.InvalidProtocolBufferException;
import redis.clients.jedis.BinaryJedis;
import protos.Reading4Java;
import java.io.IOException;
import java.util.List;
public class SimpleSubByte {
public static Reading4Java.ReadingRaw trRaw = null;
public static void main(String[] args) {
BinaryJedis binaryJedis = new BinaryJedis("test.id.local");
while (true) {
List<byte[]> byteArray = binaryJedis.brpop(0, "testID".getBytes());
for (byte[] e : byteArray) {
// System.out.println(e);
try {
trRaw = Reading4Java.ReadingRaw.parseFrom(e);
} catch (InvalidProtocolBufferException e1) {
e1.printStackTrace();
}
System.out.println(trRaw);
}
}
}
}
Protobuf文件python:
package ttm
message ReadingRaw {
required string gw_id = 1; // gateway id (e. g. mac address)
required bytes raw_data = 2; // raw data from serial interface
optional int64 timestamp = 3; // timestamp of data reading from sensor device
}
java协议文件:
package protos;
option java_outer_classname = "TireReading4Java";
message TireReadingRaw {
required string gw_id = 1; // gateway id (e. g. mac address)
required bytes raw_data = 2;
optional int64 timestamp = 3;
}
目前没有回答
相关问题 更多 >
编程相关推荐