summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2013-08-26 17:26:42 +0200
committerHarald Welte <laforge@gnumonks.org>2013-08-26 17:26:42 +0200
commit48e452874c1d7158cec43b85853776ea4ddbfe06 (patch)
tree9260443bb9dbeb05ac8338e593f521ddbdc569fd
parenta5dfd5b4491f318db734617024c122f104a28ac5 (diff)
xua_codec: convert integer to binary and truncate binary to length
-rw-r--r--src/xua_codec.erl6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/xua_codec.erl b/src/xua_codec.erl
index 7fb3103..ad5cbd3 100644
--- a/src/xua_codec.erl
+++ b/src/xua_codec.erl
@@ -89,10 +89,14 @@ encode_xua_opts([{Iei, Attr}|Tail], Bin) ->
OptBin = encode_xua_opt(Iei, Attr),
encode_xua_opts(Tail, <<Bin/binary, OptBin/binary>>).
+% convert integer parameters to binary before continuing
+encode_xua_opt(Iei, {LenIn, Data}) when is_integer(Iei), is_integer(Data) ->
+ encode_xua_opt(Iei, {LenIn, <<Data:LenIn/big-integer-unit:8>>});
+
encode_xua_opt(Iei, {LenIn, Data}) when is_integer(Iei), is_binary(Data) ->
Length = LenIn + 4,
PadLen = get_num_pad_bytes(Length),
- <<Iei:16/big, Length:16/big, Data/binary, 0:PadLen/integer-unit:8>>;
+ <<Iei:16/big, Length:16/big, Data:LenIn/binary, 0:PadLen/integer-unit:8>>;
encode_xua_opt(Iei, Data) when is_integer(Iei), is_binary(Data) ->
Length = byte_size(Data) + 4,
PadLen = get_num_pad_bytes(Length),