View Source Protox.MergeMessage (Protox v1.7.3)
This module provides a helper function to merge messages.
Summary
Functions
Singular fields of msg
will be overwritten, if specified in from
, except for
embedded messages which will be merged. Repeated fields will be concatenated.
Functions
Singular fields of msg
will be overwritten, if specified in from
, except for
embedded messages which will be merged. Repeated fields will be concatenated.
Note that "specified" has a different meaning in protobuf 2 and 3:
2: if the singular field from
from
is nil, the value frommsg
is kept3: if the singular field from
from
is set to the default value, the value frommsg
is kept. This behaviour matches the C++ reference implementation behaviour.msg
andfrom
must be of the same type; oreither
msg
orfrom
isnil
: the non-nil message is returned; orboth are
nil
:nil
is returned
Example
iex> r1 = %Protobuf2{a: 0, s: :ONE}
iex> r2 = %Protobuf2{a: nil, s: :TWO}
iex> Protox.MergeMessage.merge(r1, r2)
%Protobuf2{a: 0, s: :TWO}
iex> Protox.MergeMessage.merge(r2, r1)
%Protobuf2{a: 0, s: :ONE}