Protocol Buffers: Protocol message end-group tag did not match expected tag.

7,752 views
Skip to first unread message

Ramon

unread,
Oct 7, 2009, 11:32:45 AM10/7/09
to Protocol Buffers, beckman...@googlemail.com
Hi there,
I recently started working with Protocol Buffers. I used the
"Addressbook" Example to become acquainted with the PBs. (http://
code.google.com/intl/de-DE/apis/protocolbuffers/docs/
javatutorial.html)
The only difference is that I use an OutputStream to write the address
book instance (in the example they used a FileOutputStream).
Everything works fine, I compiled the proto file and imported it to my
Java project and even that compiles without errors, but when my client
code tries to get (parse) the addressbook instance from the server the
following merror message appears:

com.google.protobuf.InvalidProtocolBufferException: Protocol message
end-group tag did not match expected tag.
at com.google.protobuf.InvalidProtocolBufferException.invalidEndTag
(InvalidProtocolBufferException.java:73)
at com.google.protobuf.CodedInputStream.checkLastTagWas
(CodedInputStream.java:105)
at com.google.protobuf.AbstractMessageLite$Builder.mergeFrom
(AbstractMessageLite.java:202)
at com.google.protobuf.AbstractMessage$Builder.mergeFrom
(AbstractMessage.java:664)
at protoc.Example$AddressBook.parseFrom(Example.java:929)
at protoc.Proto.createConnection(Proto.java:33)
at protoc.Proto.main(Proto.java:24)


That's the code:

(Server)

...

Person.Builder person = Person.newBuilder();
person.setName("Peter");
person.setId(5);

AddressBook.Builder addressbook = AddressBook.newBuilder();
addressbook.addPerson(person.build());

addressbook.build().writeTo(client.getOutputStream()); //
client is a Socket object
client.close();



(Client)

...

public static void createConnection() {
server = null;
try {
server = new Socket("192.168.1.30", 4141);
System.out.println("Connected to server");
AddressBook mission2 = AddressBook.parseFrom(server.getInputStream
());
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
closeConnection();
}


The proto file ...



package protoc;

option java_package = "protoc";
option java_outer_classname = "Example";



message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;

enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}

message PhoneNumber {
required string number = 1;
optional PhoneType type = 2 [default = HOME];
}

repeated PhoneNumber phone = 4;
}

message AddressBook {
repeated Person person = 1;
}


Can anyone tell me what is wrong?
I can't find my mistake ... :(

Thank you very much in advance!
Ramon

Kenton Varda

unread,
Oct 7, 2009, 3:26:34 PM10/7/09
to Ramon, Protocol Buffers, beckman...@googlemail.com
Can you verify that the bytes you are sending from the server match the ones you receive on the client?  E.g. compute a checksum and print it out on both sides so that you can compare visually.  (You may need to serialize to a byte array first in order to compute the checksum, and read into a byte array on the client before passing off to protobuf.)
Reply all
Reply to author
Forward
0 new messages