From cac106defc5060c5e485480e8003b992482d751d Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Sun, 11 Jun 2017 09:33:42 +0200 Subject: Change signature associated with dictionary @custom_type/@codecs To pass the options map through the encode. This is not backwards compatible, and dictionaries supporting @custom_types or @codecs will need to be updated. --- lib/diameter/doc/src/diameter_dict.xml | 13 +++++++------ lib/diameter/src/compiler/diameter_codegen.erl | 5 +++-- lib/diameter/test/diameter_compiler_SUITE.erl | 8 ++++---- 3 files changed, 14 insertions(+), 12 deletions(-) (limited to 'lib/diameter') diff --git a/lib/diameter/doc/src/diameter_dict.xml b/lib/diameter/doc/src/diameter_dict.xml index 9584d682c2..94016d9466 100644 --- a/lib/diameter/doc/src/diameter_dict.xml +++ b/lib/diameter/doc/src/diameter_dict.xml @@ -16,7 +16,8 @@
-20112016 +2011 +2017 Ericsson AB. All Rights Reserved. @@ -307,11 +308,11 @@ The P flag has been deprecated by &the_rfc;.

Specifies AVPs for which module Mod provides encode/decode functions. The section contents consists of AVP names. -For each such name, Mod:Name(encode|decode, Type, Data) is +For each such name, Mod:Name(encode|decode, Type, Data, Opts) is expected to provide encode/decode for values of the AVP, where Name is the name of the AVP, Type is it's type as declared in the -@avp_types section of the dictionary and Data is the value to -encode/decode.

+@avp_types section of the dictionary, Data is the value to +encode/decode, and Opts is a term that is passed through encode/decode.

Example:

@@ -328,8 +329,8 @@ Framed-IP-Address

Like @custom_types but requires the specified module to export -Mod:Type(encode|decode, Name, Data) rather than -Mod:Name(encode|decode, Type, Data).

+Mod:Type(encode|decode, Name, Data, Opts) rather than +Mod:Name(encode|decode, Type, Data, Opts).

Example:

diff --git a/lib/diameter/src/compiler/diameter_codegen.erl b/lib/diameter/src/compiler/diameter_codegen.erl index b6fc78b6cc..5a1e3ba941 100644 --- a/lib/diameter/src/compiler/diameter_codegen.erl +++ b/lib/diameter/src/compiler/diameter_codegen.erl @@ -568,11 +568,12 @@ cs_custom_avp({Mod, Key, Avps}, Dict) -> c_custom_avp(Mod, Key, AvpName, Type) -> {F,A} = custom(Key, AvpName, Type), - {?clause, [?VAR('T'), ?VAR('Data'), ?Atom(AvpName), ?VAR('_')], + {?clause, [?VAR('T'), ?VAR('Data'), ?Atom(AvpName), ?VAR('Opts')], [], [?APPLY(?A(Mod), ?A(F), [?VAR('T'), ?Atom(A), - ?VAR('Data')])]}. + ?VAR('Data'), + ?VAR('Opts')])]}. custom(custom_types, AvpName, Type) -> {AvpName, Type}; diff --git a/lib/diameter/test/diameter_compiler_SUITE.erl b/lib/diameter/test/diameter_compiler_SUITE.erl index 76340d65ff..dea14e3870 100644 --- a/lib/diameter/test/diameter_compiler_SUITE.erl +++ b/lib/diameter/test/diameter_compiler_SUITE.erl @@ -39,7 +39,7 @@ -export([dict/0]). %% fake dictionary module %% dictionary callbacks for flatten2/1 --export(['A1'/3, 'Unsigned32'/3]). +-export(['A1'/4, 'Unsigned32'/4]). -define(base, "base_rfc3588.dia"). -define(util, diameter_util). @@ -552,13 +552,13 @@ flatten2(_Config) -> T <- [encode, decode], M <- [M2, M3], Ref <- [make_ref()], - RC <- [M:avp(T, Ref, A, [])], + RC <- [M:avp(T, Ref, A, #{})], RC /= {T, Ref}]. -'A1'(T, 'Unsigned32', Ref) -> +'A1'(T, 'Unsigned32', Ref, _Opts) -> {T, Ref}. -'Unsigned32'(T, 'A3', Ref) -> +'Unsigned32'(T, 'A3', Ref, _Opts) -> {T, Ref}. load_forms(Forms) -> -- cgit v1.2.3