'InvalidProtocolBufferException when parsing protobuf - invalid tag (zero)
I have a protobuf message which cribs while being parsed.
I ran the client and server on the same machine and serialized the byte stream.
I compare this with the received byte array using Arrays.equal in java. It says that they are equal.
My protobuf has just a single fixed32 field storing an IP address.
I used both google protobuf 2.4.1 and 2.5.0 versions with no success. Anything I am missing here?
Stacktrace:
com.google.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).
at com.google.protobuf.InvalidProtocolBufferException.invalidTag(InvalidProtocolBufferException.java:89)
at com.google.protobuf.CodedInputStream.readTag(CodedInputStream.java:108)
... ...
Protobuf Code:
message IpMessage {
required fixed32 ip = 1;
}
Compilation:
protoc --java_out=. ip-message.proto
To parse the message, I use:
IpMessage.parseFrom(receivedPkt); //receivedPkt is byte[]
Solution 1:[1]
This error appears if your code parses wrong protobuf message at current binary file location. In your case above, current receivedPkt isn't a IpMessage.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Linh Dao |
