i believe this is where Foo.newBuilder(Foo oldFoo) comes into play.  PB 
messages once built are immutable so instead you create a builder around an 
immutable Foo, change what you want through the builder's methods, then build a 
new (immutable) message using Builder.build().
there's also the method foo.toBuilder() which will do the same thing.


________________________________
From: marco gaddoni <marco.gadd...@gmail.com>
To: protobuf@googlegroups.com
Sent: Monday, October 10, 2011 8:44 AM
Subject: [protobuf] creating a message from another but changing only one field



Hello, 

i am using protocol buffers to comunicate between two programs,
one in c# and the other in c++.

it is working well. 

i have a generic question with the c# (and i think the java) api:
how do you create a different message from an existing one
but changin only one field?

say that i have

message foo {
 ..message baz {
....int32 f1 = 1;
..}

..required baz c1;
..required int32 f2;
}

and i have a message in java Foo msg;
how do i create a new message identical to 
msg but with f1 different ?

in my code i have to write a lot of code
and that code is fragile because i have to 
.Merge mostly field by field everything and if i 
change the structure of the message adding one
field i have to change my code.

there is another way to do it ?

...




-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/protobuf/-/DPAr9H49nL8J.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to