Hello,

Following up on the documentation on *Singular Message Fields* (link 
<https://protobuf.dev/reference/python/python-generated/#embedded_message>) 
and its examples, I’m unclear on passing messages to the initializer. 
Building on the existing example:

message Foo { optional Bar bar = 1; } message Bar { optional int32 i = 1; }

I am not supposed to use

foo = Foo() foo.bar = Bar() # WRONG!

but what about

foo = Foo(bar=Bar(i=5))

In this case, will the generated initializer use e.g. *CopyFrom()* (docs 
<https://googleapis.dev/python/protobuf/latest/google/protobuf/message.html#google.protobuf.message.Message.CopyFrom>)
 
correctly? Or is the recommendation to use:

foo = Foo() bar = Bar*()*foo.bar.CopyFrom*(*bar*)*

The suggestion to write directly to fields of *Bar* can become tedious, 
particulalry if *Bar* is more complex and I’d like to compose messages form 
other messages.

Much thanks!
Jens

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/ae70c5b1-2694-4b1a-9b6b-81a2213117b7n%40googlegroups.com.

Reply via email to