aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src/asn1rt_ber_bin_v2.erl
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2011-07-22 16:56:21 +0200
committerLukas Larsson <[email protected]>2011-08-01 17:29:45 +0200
commitdab9296e05c7b1ffa4e12a270c41741adb1da383 (patch)
tree782d1454830145c985e70afc8313b2d72e9f1ad1 /lib/asn1/src/asn1rt_ber_bin_v2.erl
parent8649b9257876d1b016746126c95c9e803a680e5d (diff)
downloadotp-dab9296e05c7b1ffa4e12a270c41741adb1da383.tar.gz
otp-dab9296e05c7b1ffa4e12a270c41741adb1da383.tar.bz2
otp-dab9296e05c7b1ffa4e12a270c41741adb1da383.zip
Create a nif for ber encode
Diffstat (limited to 'lib/asn1/src/asn1rt_ber_bin_v2.erl')
-rw-r--r--lib/asn1/src/asn1rt_ber_bin_v2.erl22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/asn1/src/asn1rt_ber_bin_v2.erl b/lib/asn1/src/asn1rt_ber_bin_v2.erl
index 4c75b5918f..4797263ca7 100644
--- a/lib/asn1/src/asn1rt_ber_bin_v2.erl
+++ b/lib/asn1/src/asn1rt_ber_bin_v2.erl
@@ -128,15 +128,25 @@
% encode(Tlv) ->
% encode_constructed(Tlv).
+encode(Tlv) when is_binary(Tlv) ->
+ Tlv;
encode([Tlv]) ->
encode(Tlv);
-encode({TlvTag,TlvVal}) when is_list(TlvVal) ->
+encode(Tlv) ->
+ case is_nif_loadable() of
+ true ->
+ asn1rt_nif:encode_ber_tlv(Tlv);
+ false ->
+ encode_erl(Tlv)
+ end.
+
+encode_erl([Tlv]) ->
+ encode_erl(Tlv);
+encode_erl({TlvTag,TlvVal}) when is_list(TlvVal) ->
%% constructed form of value
encode_tlv(TlvTag,TlvVal,?CONSTRUCTED);
-encode({TlvTag,TlvVal}) ->
- encode_tlv(TlvTag,TlvVal,?PRIMITIVE);
-encode(Bin) when is_binary(Bin) ->
- Bin.
+encode_erl({TlvTag,TlvVal}) ->
+ encode_tlv(TlvTag,TlvVal,?PRIMITIVE).
encode_tlv(TlvTag,TlvVal,Form) ->
Tag = encode_tlv_tag(TlvTag,Form),
@@ -155,7 +165,7 @@ encode_tlv_val(Bin) ->
{Bin,size(Bin)}.
encode_tlv_list([Tlv|Tlvs],Acc) ->
- EncTlv = encode(Tlv),
+ EncTlv = encode_erl(Tlv),
encode_tlv_list(Tlvs,[EncTlv|Acc]);
encode_tlv_list([],Acc) ->
Bin=list_to_binary(lists:reverse(Acc)),