Exgencode.Pdu.encode
You're seeing just the function
encode
, go back to Exgencode.Pdu module for more information.
Link to this function
encode(pdu, version \\ nil)
Specs
encode(Exgencode.pdu(), nil | Version.version()) :: binary()
Encode the Elixir structure into a binary give the protocol version.
Examples:
iex> Exgencode.Pdu.encode(%TestPdu.PzTestMsg{otherTestField: 100})
<< 1 :: size(12), 100 :: size(24), 15 :: size(8), 10 :: size(28) >>
iex> Exgencode.Pdu.encode(%TestPdu.PzTestMsg{testField: 99, otherTestField: 100})
<< 99 :: size(12), 100 :: size(24), 15 :: size(8), 10 :: size(28) >>
Version number can be optionally added to control the encoding of the PDU and exclude certain fields if the version number is lower that specified.
pdu = %TestPdu.VersionedMsg{newerField: 111, evenNewerField: 7}
assert << 10 :: size(16), 111 :: size(8), 14 :: size(8) >> == Exgencode.Pdu.encode(pdu)
assert << 10 :: size(16) >> == Exgencode.Pdu.encode(pdu, "1.0.0")
assert << 10 :: size(16), 111 :: size(8) >> == Exgencode.Pdu.encode(pdu, "2.0.0")
Examples:
iex> Exgencode.Pdu.encode(%TestPdu.VersionedMsg{newerField: 111, evenNewerField: 7}, "1.0.0")
<< 10 :: size(16) >>
iex> Exgencode.Pdu.encode(%TestPdu.VersionedMsg{newerField: 111, evenNewerField: 7}, "2.0.0")
<< 10 :: size(16), 111 :: size(8) >>