From 76ad80f52981449af3c79fdf5b298e4c8d817788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 20 Dec 2012 12:13:47 +0100 Subject: Refactor decoding of BIT STRINGs Refactor decoding of BIT STRINGs so that the run-time code does not spend testing conditions that are known already at compile-time (which wastes time and produces unnecessary Dialyzer warnings). There are three ways to decode BIT STRINGs: 1) To a list of bit names (and {bit,Position} for unnamed positions) if the BIT STRING type has any bit names. 2a) To a list of ones and zeros if there are no named bits, and the compact_bit_string option was NOT given. 2b) To a {Unused,Bin} tuple if there are no named bits compact_bit_string option WAS given. Structure the decoding functions in the same way. --- lib/asn1/src/asn1ct_gen_ber_bin_v2.erl | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'lib/asn1/src/asn1ct_gen_ber_bin_v2.erl') diff --git a/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl b/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl index 0826384365..e7414a2040 100644 --- a/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl +++ b/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl @@ -518,19 +518,8 @@ gen_dec_prim(Erules,Att,BytesVar,DoTag,TagIn,Form,OptOrMand) -> need(decode_enumerated, 3); 'REAL' -> ok; - {'BIT STRING',NamedNumberList} -> - case get(compact_bit_string) of - true -> - emit(["decode_compact_bit_string(", - BytesVar,",",{asis,Constraint},",", - {asis,NamedNumberList},","]), - need(decode_compact_bit_string, 4); - _ -> - emit(["decode_bit_string(",BytesVar,",", - {asis,Constraint},",", - {asis,NamedNumberList},","]), - need(decode_bit_string, 4) - end; + {'BIT STRING',_NamedNumberList} -> + ok; 'NULL' -> emit(["decode_null(",BytesVar,","]), need(decode_null, 2); @@ -634,6 +623,8 @@ gen_dec_prim(Erules,Att,BytesVar,DoTag,TagIn,Form,OptOrMand) -> _ when is_list(DoTag) -> {asis,DoTag} end, case NewTypeName of + {'BIT STRING',NNL} -> + gen_dec_bit_string(BytesVar, Constraint, NNL, TagStr); 'REAL' -> asn1ct_name:new(tmpbuf), emit(["begin",nl, @@ -660,6 +651,20 @@ int_constr(SingleValue,[]) -> SingleValue; int_constr(SV,VR) -> [SV,VR]. + +gen_dec_bit_string(BytesVar, _Constraint, [_|_]=NNL, TagStr) -> + call(decode_named_bit_string, + [BytesVar,{asis,NNL},TagStr]); +gen_dec_bit_string(BytesVar, Constraint, [], TagStr) -> + case get(compact_bit_string) of + true -> + call(decode_compact_bit_string, + [BytesVar,{asis,Constraint},TagStr]); + _ -> + call(decode_legacy_bit_string, + [BytesVar,{asis,Constraint},TagStr]) + end. + %% Object code generating for encoding and decoding %% ------------------------------------------------ -- cgit v1.2.3