exprotobuf icon indicating copy to clipboard operation
exprotobuf copied to clipboard

Support in .new for composite messages

Open meadoch1 opened this issue 9 years ago • 2 comments

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

meadoch1 avatar Sep 09 '16 20:09 meadoch1

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

Ch4s3 avatar Feb 01 '18 19:02 Ch4s3

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.

Ch4s3 avatar Feb 01 '18 19:02 Ch4s3