Google Protocol Buffer 3.0 - Serialized Length Is 0 After set_field(...)

I am using Google Protobuf 3.0.0. and ZeroMQ to achieve a connection between a server and some clients. So, my proto file looks something like this:

// message Request{} omitted
message Response{
 enum MessageType{
   Type1 = 0;
   Type2 = 1;
   Type3 = 2;
 enum ConfirmationCode{
   OK = 0;
   Error1 = 1;
   Error2 = 2;
 MessageType Type = 1;
 repeated someField1 field1 = 2;
 // ... some code omitted
 ConfirmationCode Confirm = 3;

As you can see, in ProtoBuf 3 there are no longer required or optional fields and I do not use any defaults. Now, I ran into some troubles when serializing some Protobuf messages and trying to send them over ZMQ. The serialization done by google::protobuf::message_lite::SerializeToString(...) does not fail but still, this method and google::protobuf::message_lite::SerializeAsString() produce empty strings, so I thought that maybe not a single field was set in my response before serializing and I introduced a method similar to the following

void InitResponse(Response& resp)

to be sure that at least some fields were present. Still, before and after calling this method, my serialized response has a length of 0. I also tried using google::protobuf::Message::DebugString() but I think this method does not print every field present, since I always end up printing empty strings.

Why do my serialized messages end up empty if the serialization does not fail?

1 answer