I was just wondering, why anybody hasn't gone through the problem I recently have in connection with google protobufs, but after extensive googling, reading the documentation of google's manual page and searching in Stackoverflow-DB, I did not found a solution.
I am using proto2-c++-API on an Ubuntu 14.04.3 LTS, compiling with gcc/g++ over cmake-files.
I have an application that reads binary (serialized) google protocol buffer messages from a file. The programm's purpose then is to send the messages (without deserialization) to another application, which proceeds with processing the actual data.
I now would like to modify some of the messages, read from the file, so I can test the functionality of the second application. Unfortunately my message includes a lot of nested messages, so after deserializing I have to call something like
message().a().b().c()....x().value();
to be able to work with the actual data.
My question now is, how I can change the value of x
without creating another message of type message
where I also have to create all sub-messages (a,b,c...
) and allocate these with the respective predecessor like in the following pseudo-code?!
a = new a();
b = new b();
c = new c();
...
v = new v();
w = new w();
x = new x();
x.set_value();
w.set_allocated_x_value(x);
v.set_allocated_w_value(w);
...
a.set_allocated_b_value(b);
message.set_allocated_a_value(a);
...
/* forward message to second application */
...
delete x;
delete w;
...
delete a;
Obviously it is not possible to call set_value
directly on the message
-objects, respectively its sub-objects like message().a().b().c()....x().set_value();
, as one would violate the const requirements of the auto-generated protobuf-messages, where it is not allowed to call a setter-method on a const object: error: passing xxx as 'this' argument of xxx discards qualifiers
I would appreciate any creative solution to avoid implementing the recursive new-set_allocated-delete
code, posted above.
Thanks in advance