Support in .new for composite messages
The library does not appear to instantiate children messages for a message which has other messages declared as an attribute. For example, using the Messages.Msg definition in the Readme, calling
Messages.Msg.new(version: :'V2', sub: [value: 2])
results in the following
iex(8)> msg = Messages.Msg.new(version: :'V2', sub: [value: 2])
%Messages.Msg{sub: [value: 2], version: :V2}
It appears that the value for "sub" is just taken at face value and assigned rather than interpreted as another set of values for a different type of message. I would expect that it could recurse through the embeded layers and construct the sub-message(s) as long as they are supplying values of the correct type.
Is there a better way to deal with this?
Thanks
msg = Messages.Msg.new(version: :'V2', sub: [value: 2])
%Messages.Msg{sub: [value: 2], version: :V2}
This gives me anargument error with for :gpb.encode_msg/2
Ahh, it seem like a struct is needed.
msg = Messages.Msg.new(version: :'V2', sub: %Messages.Msg. SubMsg{value: 1})
The above works for me.