diff options
author | Lukas Larsson <[email protected]> | 2011-07-22 16:56:21 +0200 |
---|---|---|
committer | Lukas Larsson <[email protected]> | 2011-08-01 17:29:45 +0200 |
commit | dab9296e05c7b1ffa4e12a270c41741adb1da383 (patch) | |
tree | 782d1454830145c985e70afc8313b2d72e9f1ad1 /lib/asn1/src | |
parent | 8649b9257876d1b016746126c95c9e803a680e5d (diff) | |
download | otp-dab9296e05c7b1ffa4e12a270c41741adb1da383.tar.gz otp-dab9296e05c7b1ffa4e12a270c41741adb1da383.tar.bz2 otp-dab9296e05c7b1ffa4e12a270c41741adb1da383.zip |
Create a nif for ber encode
Diffstat (limited to 'lib/asn1/src')
-rw-r--r-- | lib/asn1/src/asn1rt_ber_bin_v2.erl | 22 | ||||
-rw-r--r-- | lib/asn1/src/asn1rt_nif.erl | 8 |
2 files changed, 22 insertions, 8 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)), diff --git a/lib/asn1/src/asn1rt_nif.erl b/lib/asn1/src/asn1rt_nif.erl index 8580c70e6b..de1fb94816 100644 --- a/lib/asn1/src/asn1rt_nif.erl +++ b/lib/asn1/src/asn1rt_nif.erl @@ -22,7 +22,8 @@ %% Nif interface for asn1 -export([encode_per_complete/1, - decode_ber_tlv/1]). + decode_ber_tlv/1, + encode_ber_tlv/1]). -on_load(load_nif/0). @@ -76,8 +77,11 @@ load_nif() -> Status end. -encode_per_complete(_Binary) -> +encode_per_complete(_TagValueList) -> erlang:nif_error({nif_not_loaded,module,?MODULE,line,?LINE}). decode_ber_tlv(_Binary) -> erlang:nif_error({nif_not_loaded,module,?MODULE,line,?LINE}). + +encode_ber_tlv(_TagValueList) -> + erlang:nif_error({nif_not_loaded,module,?MODULE,line,?LINE}). |