diff options
author | Anders Svensson <[email protected]> | 2017-04-22 08:46:48 +0200 |
---|---|---|
committer | Anders Svensson <[email protected]> | 2017-06-12 16:13:52 +0200 |
commit | 2ae059913dc332e5655f44d1b2292342cb470fc1 (patch) | |
tree | 4301b9a6d822b60380ee24425315066ef9187cc6 | |
parent | c83d5ac4d4df41924b52cb577c255cd0c23f36ed (diff) | |
download | otp-2ae059913dc332e5655f44d1b2292342cb470fc1.tar.gz otp-2ae059913dc332e5655f44d1b2292342cb470fc1.tar.bz2 otp-2ae059913dc332e5655f44d1b2292342cb470fc1.zip |
Don't prepend bit for sub binary optimization
-rw-r--r-- | lib/diameter/include/diameter_gen.hrl | 17 | ||||
-rw-r--r-- | lib/diameter/src/base/diameter_codec.erl | 17 |
2 files changed, 16 insertions, 18 deletions
diff --git a/lib/diameter/include/diameter_gen.hrl b/lib/diameter/include/diameter_gen.hrl index fadc6f2b60..968cf66ea7 100644 --- a/lib/diameter/include/diameter_gen.hrl +++ b/lib/diameter/include/diameter_gen.hrl @@ -378,8 +378,11 @@ d(Name, Avp, Acc) -> %% Remove any extra bit that was added in diameter_codec to induce a %% 5014 error. -trim(#diameter_avp{data = <<0:1, Bin/binary>>} = Avp) -> - Avp#diameter_avp{data = Bin}; +trim(#diameter_avp{data = Data} = Avp) -> + Avp#diameter_avp{data = trim(Data)}; + +trim({5014, Bin}) -> + Bin; trim(Avps) when is_list(Avps) -> @@ -569,9 +572,9 @@ pack_avp(_, Arity, Avp, Acc) -> %% payload for the AVP's type, but in this case we don't know the %% type. -pack_AVP(_, #diameter_avp{data = <<0:1, Data/binary>>} = Avp, Acc) -> +pack_AVP(_, #diameter_avp{data = {5014 = RC, Data}} = Avp, Acc) -> {Rec, Failed} = Acc, - {Rec, [{5014, Avp#diameter_avp{data = Data}} | Failed]}; + {Rec, [{RC, Avp#diameter_avp{data = Data}} | Failed]}; pack_AVP(Name, #diameter_avp{is_mandatory = M, name = AvpName} = Avp, Acc) -> case pack_arity(Name, AvpName, M) of @@ -660,7 +663,7 @@ pack(L, {_, Max}, F, Avp, {Rec, Failed}) -> %% # grouped_avp/3 %% --------------------------------------------------------------------------- --spec grouped_avp(decode, avp_name(), bitstring()) +-spec grouped_avp(decode, avp_name(), binary() | {5014, binary()}) -> {avp_record(), [avp()]}; (encode, avp_name(), avp_record() | avp_values()) -> iolist() @@ -670,8 +673,8 @@ pack(L, {_, Max}, F, Avp, {Rec, Failed}) -> %% length in the header was too short (insufficient for the extracted %% header) or too long (past the end of the message). An empty payload %% is sufficient according to the RFC text for 5014. -grouped_avp(decode, _Name, <<0:1, _/binary>>) -> - throw({?TAG, {grouped, {5014, []}, []}}); +grouped_avp(decode, _Name, {5014 = RC, _Bin}) -> + throw({?TAG, {grouped, {RC, []}, []}}); grouped_avp(decode, Name, Data) -> grouped_decode(Name, diameter_codec:collect_avps(Data)); diff --git a/lib/diameter/src/base/diameter_codec.erl b/lib/diameter/src/base/diameter_codec.erl index 43cc49903d..789395abe9 100644 --- a/lib/diameter/src/base/diameter_codec.erl +++ b/lib/diameter/src/base/diameter_codec.erl @@ -617,7 +617,7 @@ collect_avps(Code, VendorId, M, P, Len, Pad, Rest, N, Acc) -> vendor_id = VendorId, is_mandatory = M, need_encryption = P, - data = <<0:1, Rest/binary>>, + data = {5014, Rest}, index = N}, [Avp | Acc] end. @@ -705,23 +705,18 @@ pack_avp(#diameter_avp{code = undefined, data = B}) Sz = min(5, size(B)), <<B:Sz/binary, 0:(5-Sz)/unit:8, Len:24, 0:(Len-8)/unit:8>>; +%% Ignoring errors in Failed-AVP or during a relay encode. +pack_avp(#diameter_avp{data = {5014, Data}} = A) -> + pack_data(Data, A); + pack_avp(#diameter_avp{data = Data} = A) -> - pack_bits(Data, A). + pack_data(Data, A). header_length(<<_:32, 1:1, _/bits>>) -> 12; header_length(_) -> 8. -%% pack_bits/2 - -%% Ignoring errors in Failed-AVP or during a relay encode. -pack_bits(<<0:1, B/binary>>, Avp) -> - pack_bits(B, Avp); - -pack_bits(Data, Avp) -> - pack_data(Data, Avp). - %% pack_data/2 pack_data(Data, #diameter_avp{code = Code, |