I am trying to parse multiple protocol buffer messages in java which are generated in vb.net
I am using the excellent protobuf-net to stream multiple messages to java as per below:
ProtoBuf.Serializer.SerializeWithLengthPrefix(Of Msg)(postStream, msg,
ProtoBuf.PrefixStyle.Base128)
In Java, I am using following code to parse the messages
final byte[] buffer = new byte[4096];
for (int c = ins.read(buffer); c >= 0; c = ins.read(buffer)) {
Msg msg = Msg.parseDelimitedFrom(new ByteArrayInputStream(buffer));
}
Problem is after first message is parsed, it throws error for parsing second time with following error:
com.google.protobuf.InvalidProtocolBufferException: While parsing a protocol message, the input ended unexpectedly in the middle of a field. This could mean either than the input has been truncated or that an embedded message misreported its own length.
Should the buffer size and message size be same? If yes, then how should I parse it, especially for large messages.
[C#]and[vb.net]as the answer doesn't appear to need to refer to either of these. - Peter Lawrey