aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter/include
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2017-04-30 10:30:59 +0200
committerAnders Svensson <[email protected]>2017-06-13 13:50:07 +0200
commit84dbccad048374e3eb1ec7372fd177eba022d108 (patch)
treeec209217c96f23d9327e08da35f721b08a23cc38 /lib/diameter/include
parent9d08b9d8d9d500259eeb808af19f9cf3d8d79fdf (diff)
downloadotp-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/include')
-rw-r--r--lib/diameter/include/diameter_gen.hrl24
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/diameter/include/diameter_gen.hrl b/lib/diameter/include/diameter_gen.hrl
index 1683d93557..83f87ea4c4 100644
--- a/lib/diameter/include/diameter_gen.hrl
+++ b/lib/diameter/include/diameter_gen.hrl
@@ -43,35 +43,39 @@
%% # encode_avps/3
%% ---------------------------------------------------------------------------
--spec encode_avps(parent_name(), parent_record() | avp_values(), term())
+-spec encode_avps(parent_name(), parent_record() | avp_values(), map())
-> iolist()
| no_return().
-encode_avps(Name, Vals, Opts)
- when is_list(Vals) ->
- encode_avps(Name, '#set-'(Vals, newrec(Name)), Opts);
-
-encode_avps(Name, Rec, Opts) ->
+encode_avps(Name, Vals, Opts) ->
try
- encode(Name, Rec, Opts)
+ encode(Name, Vals, Opts)
catch
throw: {?MODULE, Reason} ->
diameter_lib:log({encode, error},
?MODULE,
?LINE,
- {Reason, Name, Rec}),
+ {Reason, Name, Vals}),
erlang:error(list_to_tuple(Reason ++ [Name]));
error: Reason ->
Stack = erlang:get_stacktrace(),
diameter_lib:log({encode, failure},
?MODULE,
?LINE,
- {Reason, Name, Rec, Stack}),
+ {Reason, Name, Vals, Stack}),
erlang:error({encode_failure, Reason, Name, Stack})
end.
%% encode/3
+encode(Name, Vals, #{ordered_encode := false} = Opts)
+ when is_list(Vals) ->
+ lists:map(fun({F,V}) -> encode(Name, F, V, Opts) end, Vals);
+
+encode(Name, Vals, Opts)
+ when is_list(Vals) ->
+ encode(Name, '#set-'(Vals, newrec(Name)), Opts);
+
encode(Name, Rec, Opts) ->
[encode(Name, F, V, Opts) || {F,V} <- '#get-'(Rec)].
@@ -671,4 +675,4 @@ z(Name) ->
%% ---------------------------------------------------------------------------
empty(AvpName) ->
- avp(encode, zero, AvpName, _Opts = []).
+ avp(encode, zero, AvpName, _Opts = #{}).