aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter/src/base
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2013-07-30 16:48:27 +0200
committerAnders Svensson <[email protected]>2013-07-30 17:59:08 +0200
commit8e7402a8b4230d25d89ddd2492908b4206083392 (patch)
tree289008b35465740585d1ba25aed2ea3a693aa518 /lib/diameter/src/base
parentff4f753dbf02693c288d7e15cb3486359e73831f (diff)
downloadotp-8e7402a8b4230d25d89ddd2492908b4206083392.tar.gz
otp-8e7402a8b4230d25d89ddd2492908b4206083392.tar.bz2
otp-8e7402a8b4230d25d89ddd2492908b4206083392.zip
Simplify Address encode/decode
By using binary comprehensions. Add string-valued addresses to codec suite.
Diffstat (limited to 'lib/diameter/src/base')
-rw-r--r--lib/diameter/src/base/diameter_types.erl39
1 files changed, 8 insertions, 31 deletions
diff --git a/lib/diameter/src/base/diameter_types.erl b/lib/diameter/src/base/diameter_types.erl
index 7ebf891819..8c07e84777 100644
--- a/lib/diameter/src/base/diameter_types.erl
+++ b/lib/diameter/src/base/diameter_types.erl
@@ -250,13 +250,10 @@
'Address'(encode, zero) ->
<<0:48>>;
-'Address'(decode, <<1:16, B/binary>>)
- when size(B) == 4 ->
- list_to_tuple(binary_to_list(B));
-
-'Address'(decode, <<2:16, B/binary>>)
- when size(B) == 16 ->
- list_to_tuple(v6dec(B, []));
+'Address'(decode, <<A:16, B/binary>>)
+ when 1 == A, 4 == size(B);
+ 2 == A, 16 == size(B) ->
+ list_to_tuple([N || <<N:A/unit:8>> <= B]);
'Address'(decode, <<A:16, _/binary>> = B)
when 1 == A;
@@ -264,30 +261,10 @@
?INVALID_LENGTH(B);
'Address'(encode, T) ->
- ipenc(diameter_lib:ipaddr(T)).
-
-ipenc(T)
- when is_tuple(T), size(T) == 4 ->
- B = list_to_binary(tuple_to_list(T)),
- <<1:16, B/binary>>;
-
-ipenc(T)
- when is_tuple(T), size(T) == 8 ->
- B = v6enc(lists:reverse(tuple_to_list(T)), <<>>),
- <<2:16, B/binary>>.
-
-v6dec(<<N:16, B/binary>>, Acc) ->
- v6dec(B, [N | Acc]);
-
-v6dec(<<>>, Acc) ->
- lists:reverse(Acc).
-
-v6enc([N | Rest], B)
- when ?UINT(16,N) ->
- v6enc(Rest, <<N:16, B/binary>>);
-
-v6enc([], B) ->
- B.
+ Ns = tuple_to_list(diameter_lib:ipaddr(T)), %% length 4 or 8
+ A = length(Ns) div 4, %% 1 or 2
+ B = << <<N:A/unit:8>> || N <- Ns >>,
+ <<A:16, B/binary>>.
%% --------------------