diff options
author | Anders Svensson <[email protected]> | 2017-04-30 10:30:59 +0200 |
---|---|---|
committer | Anders Svensson <[email protected]> | 2017-06-13 13:50:07 +0200 |
commit | 84dbccad048374e3eb1ec7372fd177eba022d108 (patch) | |
tree | ec209217c96f23d9327e08da35f721b08a23cc38 /lib/diameter/src/base/diameter_codec.erl | |
parent | 9d08b9d8d9d500259eeb808af19f9cf3d8d79fdf (diff) | |
download | otp-84dbccad048374e3eb1ec7372fd177eba022d108.tar.gz otp-84dbccad048374e3eb1ec7372fd177eba022d108.tar.bz2 otp-84dbccad048374e3eb1ec7372fd177eba022d108.zip |
Add diameter_codec option ordered_encode
To allow list-valued messaged to be encoded in the specified order,
instead of in the dictionary order by first converting the list to a
record. This is not yet exposed in configuration.
Diffstat (limited to 'lib/diameter/src/base/diameter_codec.erl')
-rw-r--r-- | lib/diameter/src/base/diameter_codec.erl | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/diameter/src/base/diameter_codec.erl b/lib/diameter/src/base/diameter_codec.erl index 52eb10b8c2..a4d816db4e 100644 --- a/lib/diameter/src/base/diameter_codec.erl +++ b/lib/diameter/src/base/diameter_codec.erl @@ -21,6 +21,7 @@ -module(diameter_codec). -export([encode/2, + encode/3, decode/3, decode/4, collect_avps/1, @@ -67,13 +68,22 @@ %%% # encode/2 %%% --------------------------------------------------------------------------- --spec encode(module(), Msg :: term()) +encode(Mod, Msg) -> + encode(Mod, #{ordered_encode => true}, Msg). + +%%% --------------------------------------------------------------------------- +%%% # encode/3 +%%% --------------------------------------------------------------------------- + +-spec encode(module(), + map(), + Msg :: term()) -> #diameter_packet{} | no_return(). -encode(Mod, #diameter_packet{} = Pkt) -> +encode(Mod, Opts, #diameter_packet{} = Pkt) -> try - encode(Mod, _Opts = [], Pkt) + enc(Mod, Opts, Pkt) catch exit: {Reason, Stack, #diameter_header{} = H} = T -> %% Exit with a header in the reason to let the caller @@ -86,18 +96,18 @@ encode(Mod, #diameter_packet{} = Pkt) -> exit({?MODULE, encode, T}) end; -encode(Mod, Msg) -> +encode(Mod, Opts, Msg) -> Seq = diameter_session:sequence(), Hdr = #diameter_header{version = ?DIAMETER_VERSION, end_to_end_id = Seq, hop_by_hop_id = Seq}, - encode(Mod, #diameter_packet{header = Hdr, - msg = Msg}). + encode(Mod, Opts, #diameter_packet{header = Hdr, + msg = Msg}). -%% encode/3 +%% enc/3 -encode(_, Opts, #diameter_packet{msg = [#diameter_header{} = Hdr | As]} - = Pkt) -> +enc(_, Opts, #diameter_packet{msg = [#diameter_header{} = Hdr | As]} + = Pkt) -> try encode_avps(reorder(As), Opts) of Avps -> Bin = list_to_binary(Avps), @@ -126,7 +136,7 @@ encode(_, Opts, #diameter_packet{msg = [#diameter_header{} = Hdr | As]} exit({Reason, diameter_lib:get_stacktrace(), Hdr}) end; -encode(Mod, Opts, #diameter_packet{header = Hdr0, msg = Msg} = Pkt) -> +enc(Mod, Opts, #diameter_packet{header = Hdr0, msg = Msg} = Pkt) -> MsgName = rec2msg(Mod, Msg), {Code, Flags, Aid} = msg_header(Mod, MsgName, Hdr0), |