Protox.Message (Protox v1.3.1) View Source
This module provides functions to work with messages.
Link to this section 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.
Link to this section Functions
Specs
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
fromis nil, the value frommsgis kept3: if the singular field from
fromis set to the default value, the value frommsgis kept. This behaviour matches the C++ reference implementation behaviour.msgandfrommust be of the same type; oreither
msgorfromisnil: the non-nil message is returned; orboth are
nil:nilis returned
Example
iex> r1 = %Protobuf2{a: 0, s: :ONE}
iex> r2 = %Protobuf2{a: nil, s: :TWO}
iex> Protox.Message.merge(r1, r2)
%Protobuf2{a: 0, s: :TWO}
iex> Protox.Message.merge(r2, r1)
%Protobuf2{a: 0, s: :ONE}