Hi,
I have been using protobuf for a while and it worked properly. Recently I have written a new project but has this serialization issue. Here is the example:
In the .proto file, I have this definition:
------------
syntax = "proto2";
package diff_input;
message Diff{
message File{
required bool val = 1;
}
required File file = 1;
}
------------
After compiling it to .cc and .h files, I have this simple test:
-------------------------
using namespace std;
using namespace google::protobuf::io;
using namespace diff_input;
int main(){
Diff* file = new Diff();
Diff_File* input = new Diff_File();
input->set_val(true);
file->set_allocated_file(input);
int outfd = open("serial_file", O_RDWR | O_CREAT|O_TRUNC , 0666);
if(outfd == -1){
std::cout<<"Open Error\n";
}
ZeroCopyOutputStream* output = new FileOutputStream(outfd);
CodedOutputStream *p_stream = new CodedOutputStream(output);
file->SerializeWithCachedSizes(p_stream);
delete(p_stream);
delete(output);
close(outfd);
return 1;
}
-------------------------
When I run the executable, I received an error
----------------------
[libprotobuf FATAL ~/build/external.protobuf/src/external.protobuf/src/google/protobuf/wire_format_lite.cc:580] CHECK failed: (end - target) == (size):
Aborted
----------------------
However, if I commented " input->set_val(true);", I would not receive any errors.
My protoc executable is of version "libprotoc 3.5.1".
Many thanks!