thank you

You suggest that this is the best way?

..Foo oldfoo = get_from_elsewhere();

..Baz newbaz = oldfoo.c1.toBuilder().set_f1(42).Build();
..Foo newfoo = oldfoo.toBuilder().set_c1(newbaz).Build();

..send_somewhere(newfoo);

i see this problematic if i have messages nested in messages 



Il giorno lunedì 10 ottobre 2011 19:05:45 UTC+2, Ron ha scritto:
>
> 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...@gmail.com>
> *To:* prot...@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 prot...@googlegroups.com.
> To unsubscribe from this group, send email to 
> protobuf+u...@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 view this discussion on the web visit 
https://groups.google.com/d/msg/protobuf/-/3ngoA6L-e00J.
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