aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2014-05-06 15:38:14 +0200
committerBjörn Gustavsson <[email protected]>2014-06-05 13:46:28 +0200
commit4e88e704e902c774327d08f40f310d3d1572f2b6 (patch)
tree3d09e6a1009c2ce93ef045c3252f06845e70da1a /lib/asn1
parent02ac5e7084da25763ab823cd02cd461a0f7511bd (diff)
downloadotp-4e88e704e902c774327d08f40f310d3d1572f2b6.tar.gz
otp-4e88e704e902c774327d08f40f310d3d1572f2b6.tar.bz2
otp-4e88e704e902c774327d08f40f310d3d1572f2b6.zip
BER: Optimize encoding of ENUMERATED
This will also eliminate a dialyzer warning.
Diffstat (limited to 'lib/asn1')
-rw-r--r--lib/asn1/src/asn1ct_gen_ber_bin_v2.erl8
-rw-r--r--lib/asn1/src/asn1rtt_ber.erl10
2 files changed, 7 insertions, 11 deletions
diff --git a/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl b/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl
index bf5d649029..c78b164466 100644
--- a/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl
+++ b/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl
@@ -266,14 +266,20 @@ emit_enc_enumerated_cases(L, Tags) ->
emit_enc_enumerated_cases(L, Tags, noext).
emit_enc_enumerated_cases([{EnumName,EnumVal}|T], Tags, Ext) ->
+ Bytes = encode_pos_integer(EnumVal, []),
+ Len = length(Bytes),
emit([{asis,EnumName}," -> ",
- {call,ber,encode_enumerated,[EnumVal,Tags]},";",nl]),
+ {call,ber,encode_tags,[Tags,{asis,Bytes},Len]},";",nl]),
emit_enc_enumerated_cases(T, Tags, Ext);
emit_enc_enumerated_cases([], _Tags, _Ext) ->
%% FIXME: Should extension be handled?
emit([{curr,enumval}," -> exit({error,{asn1, {enumerated_not_in_range,",{curr, enumval},"}}})"]),
emit([nl,"end"]).
+encode_pos_integer(0, [B|_Acc] = L) when B < 128 ->
+ L;
+encode_pos_integer(N, Acc) ->
+ encode_pos_integer(N bsr 8, [N band 255|Acc]).
%%===============================================================================
%%===============================================================================
diff --git a/lib/asn1/src/asn1rtt_ber.erl b/lib/asn1/src/asn1rtt_ber.erl
index a85d50bde4..bfa4253b3d 100644
--- a/lib/asn1/src/asn1rtt_ber.erl
+++ b/lib/asn1/src/asn1rtt_ber.erl
@@ -28,7 +28,6 @@
encode_integer/2,encode_integer/3,
decode_integer/2,
number2name/2,
- encode_enumerated/2,
encode_unnamed_bit_string/2,encode_unnamed_bit_string/3,
encode_named_bit_string/3,encode_named_bit_string/4,
encode_bit_string/4,
@@ -711,15 +710,6 @@ number2name(Int, NamedNumberList) ->
Int
end.
-
-%%============================================================================
-%% Enumerated value, ITU_T X.690 Chapter 8.4
-
-%% encode enumerated value
-%%============================================================================
-encode_enumerated(Val, TagIn) when is_integer(Val) ->
- encode_tags(TagIn, encode_integer(Val)).
-
%%============================================================================
%% Bitstring value, ITU_T X.690 Chapter 8.6
%%