aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src/asn1ct_gen_per.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2012-12-20 12:13:47 +0100
committerBjörn Gustavsson <[email protected]>2013-01-22 19:20:12 +0100
commit76ad80f52981449af3c79fdf5b298e4c8d817788 (patch)
treee717f03e019d2a8089e9adfe424b8700067a98bc /lib/asn1/src/asn1ct_gen_per.erl
parentfbcb7fe589edbfe79d10d7fe01be8a9f77926b89 (diff)
downloadotp-76ad80f52981449af3c79fdf5b298e4c8d817788.tar.gz
otp-76ad80f52981449af3c79fdf5b298e4c8d817788.tar.bz2
otp-76ad80f52981449af3c79fdf5b298e4c8d817788.zip
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.
Diffstat (limited to 'lib/asn1/src/asn1ct_gen_per.erl')
-rw-r--r--lib/asn1/src/asn1ct_gen_per.erl30
1 files changed, 22 insertions, 8 deletions
diff --git a/lib/asn1/src/asn1ct_gen_per.erl b/lib/asn1/src/asn1ct_gen_per.erl
index 5dda5e9c5d..b7f3a12040 100644
--- a/lib/asn1/src/asn1ct_gen_per.erl
+++ b/lib/asn1/src/asn1ct_gen_per.erl
@@ -1088,6 +1088,28 @@ gen_dec_imm_1('ASN1_OPEN_TYPE', Constraint, Aligned) ->
imm_decode_open_type(Constraint, Aligned);
gen_dec_imm_1('ANY', _Constraint, Aligned) ->
imm_decode_open_type([], Aligned);
+gen_dec_imm_1({'BIT STRING',NNL}, Constr0, Aligned) ->
+ Constr = get_constraint(Constr0, 'SizeConstraint'),
+ Imm = asn1ct_imm:per_dec_raw_bitstring(Constr, Aligned),
+ {F,A} = case NNL of
+ [] ->
+ case get(compact_bit_string) of
+ true ->
+ {decode_compact_bit_string,1};
+ _ ->
+ {decode_legacy_bit_string,1}
+ end;
+ [_|_] ->
+ {decode_named_bit_string,2}
+ end,
+ Dec = fun(V, Buf) ->
+ As = case A of
+ 1 -> [V];
+ 2 -> [V,{asis,NNL}]
+ end,
+ emit(["{",{call,per_common,F,As},com,Buf,"}"])
+ end,
+ {call,Dec,Imm};
gen_dec_imm_1('BOOLEAN', _Constr, _Aligned) ->
asn1ct_imm:per_dec_boolean();
gen_dec_imm_1({'ENUMERATED',{Base,Ext}}, _Constr, Aligned) ->
@@ -1120,14 +1142,6 @@ gen_dec_prim_1(Erule,
#type{def=Typename,constraint=Constraint}=Att,
BytesVar) ->
case Typename of
- {'BIT STRING',NamedNumberList} ->
- Func = case get(compact_bit_string) of
- true -> decode_compact_bit_string;
- _ -> decode_bit_string
- end,
- call(Erule, Func,
- [BytesVar,{asis,Constraint},
- {asis,NamedNumberList}]);
'NULL' ->
emit({"{'NULL',",BytesVar,"}"});
'OBJECT IDENTIFIER' ->