Enrico Viappiani
unread,Jul 10, 2011, 10:07:44 AM7/10/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Protocol Buffers
I've got a java server and a c++ client, client sends a message to the
server.
In a first moment we had the message structure made by simple format
like strings or integers, and the message sending/receiving with
serialization and deserialization were working perfectly.
Nowadays we added a "enum" in the structure and now on the java side,
the deserialization doesn't work anymore:
c++ client sending:
bool Client::SendMsg(const char* pStr)
{
if (send(m_iSock, (char *) pStr, strlen(pStr), 0) == -1) //
send(id_socket,stringa,lunghezza stringa,flags)
{
perror("Client::SendString, send");
return false;
}
return true
}
//on the client'smain
ss=(const char*)malloc(1000);
ss = obj.c_str();
mylink.SendMsg(ss);
java server receiving:
public int ReceiveMsg() throws IOException
{
InputStream InMsg = sock.getInputStream();
ProtoMessage Msg = ProtoMessage.parseFrom(InMsg); //THIS
THROWS THE ERROR
sock.close;
}
the error is:
Exception in thread "main"
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.
at
com.google.protobuf.InvalidProtocolBufferException.truncatedMessage(InvalidProtocolBufferException.java:
49)
at
com.google.protobuf.CodedInputStream.refillBuffer(CodedInputStream.java:
711)
at
com.google.protobuf.CodedInputStream.readRawByte(CodedInputStream.java:
734)
at
com.google.protobuf.CodedInputStream.readRawVarint32(CodedInputStream.java:
338)
at
com.google.protobuf.CodedInputStream.readInt32(CodedInputStream.java:
198)
On the other side otherwise c++ client can deserialize the stream
perfectly.
I'm gettin mad, without the enum the send/receive is working!
any ideas?
thanks in advance
Enrico