aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter/src/base/diameter_gen.erl
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2017-07-06 12:07:36 +0200
committerAnders Svensson <[email protected]>2017-08-03 17:14:27 +0200
commitd52611e9bd0628affa7b4f56a6126e4a99b69a7a (patch)
tree6dc7cae62bd1ba105e4f2e2ccfd32ed923c9dceb /lib/diameter/src/base/diameter_gen.erl
parent1b3b64af3d9a5441b6da37cf4e97b59cb043f33b (diff)
downloadotp-d52611e9bd0628affa7b4f56a6126e4a99b69a7a.tar.gz
otp-d52611e9bd0628affa7b4f56a6126e4a99b69a7a.tar.bz2
otp-d52611e9bd0628affa7b4f56a6126e4a99b69a7a.zip
Let messages and grouped AVPs be decoded to lists
That is, decode to the same format that encode already accepts. Only a message has its name at the head of the list since AVPs are already name/value pairs.
Diffstat (limited to 'lib/diameter/src/base/diameter_gen.erl')
-rw-r--r--lib/diameter/src/base/diameter_gen.erl35
1 files changed, 23 insertions, 12 deletions
diff --git a/lib/diameter/src/base/diameter_gen.erl b/lib/diameter/src/base/diameter_gen.erl
index be2e221b7e..2381b73d07 100644
--- a/lib/diameter/src/base/diameter_gen.erl
+++ b/lib/diameter/src/base/diameter_gen.erl
@@ -178,14 +178,17 @@ enc_AVP(_Name, {_Dict, _AvpName, _Data} = T, Opts, _) ->
-> {parent_record(), [avp()], Failed}
when Failed :: [{5000..5999, #diameter_avp{}}].
-decode_avps(Name, Recs, #{module := Mod} = Opts) ->
+decode_avps(Name, Recs, #{module := Mod, record_decode := Fmt} = Opts) ->
{Avps, {Rec, AM, Failed}}
= mapfoldl(fun(T,A) -> decode(Name, Opts, Mod, T, A) end,
- {newrec(Mod, Name, Opts), #{}, []},
+ {newrec(Mod, Name, Fmt), #{}, []},
Recs),
%% AM counts the number of top-level AVPs, which missing/4 then
%% uses when adding 5005 errors.
- {Rec, Avps, Failed ++ missing(Name, Opts, Mod, AM)}.
+ Arities = Mod:avp_arity(Name),
+ {reformat(Rec, Arities, Fmt),
+ Avps,
+ Failed ++ missing(Arities, Opts, Mod, AM)}.
%% Append 5005 errors so that errors are reported in the order
%% encountered. Failed-AVP should typically contain the first
@@ -216,10 +219,10 @@ mapfoldl(_, Acc, [], List) ->
%% Vendor-Id if applicable. The value field of the missing AVP
%% should be of correct minimum length and contain zeros.
-missing(Name, Opts, Mod, AM) ->
+missing(Arities, Opts, Mod, AM) ->
lists:foldl(fun(T,A) -> missing(T, AM, Opts, Mod, A) end,
[],
- Mod:avp_arity(Name)).
+ Arities).
%% missing/5
@@ -631,7 +634,7 @@ too_many(FieldName, M, Map) ->
%% set/5
-set(_, _, _, _, undefined = No) ->
+set(_, _, _, _, false = No) ->
No;
set(1, F, Value, _, Map)
@@ -743,20 +746,28 @@ empty(Name, #{module := Mod} = Opts) ->
%% newrec/3
-newrec(_, _, #{record_decode := false}) ->
- undefined;
+newrec(_, _, false = No) ->
+ No;
-newrec(_, Name, #{record_decode := map}) ->
- #{':name' => Name};
+newrec(Mod, Name, true) ->
+ newrec(Mod, Name);
-newrec(Mod, Name, _) ->
- newrec(Mod, Name).
+newrec(_, Name, _) ->
+ #{':name' => Name}.
%% newrec/2
newrec(Mod, Name) ->
Mod:'#new-'(Mod:name2rec(Name)).
+%% reformat/3
+
+reformat(Map, Arities, list) ->
+ [{F,V} || {F,_} <- Arities, #{F := V} <- [Map]];
+
+reformat(Rec, _, _) ->
+ Rec.
+
%% def/1
def(1) ->