aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src/asn1ct_gen_per.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2013-01-08 10:56:27 +0100
committerBjörn Gustavsson <[email protected]>2013-01-23 15:22:56 +0100
commit74cee7dc1cc5b0332cd851da4953ebbb98224b5f (patch)
treeff539fdce7055f51fb437bc906358f073d77a620 /lib/asn1/src/asn1ct_gen_per.erl
parent625d2b01dcaa0b15cc9ff7f98438bcd81a5bddc8 (diff)
downloadotp-74cee7dc1cc5b0332cd851da4953ebbb98224b5f.tar.gz
otp-74cee7dc1cc5b0332cd851da4953ebbb98224b5f.tar.bz2
otp-74cee7dc1cc5b0332cd851da4953ebbb98224b5f.zip
By default, encode BIT STRING to bitstrings
Add the option 'legacy_bit_string' to decode to the old list format.
Diffstat (limited to 'lib/asn1/src/asn1ct_gen_per.erl')
-rw-r--r--lib/asn1/src/asn1ct_gen_per.erl51
1 files changed, 32 insertions, 19 deletions
diff --git a/lib/asn1/src/asn1ct_gen_per.erl b/lib/asn1/src/asn1ct_gen_per.erl
index a43975a308..b38af3306a 100644
--- a/lib/asn1/src/asn1ct_gen_per.erl
+++ b/lib/asn1/src/asn1ct_gen_per.erl
@@ -1099,25 +1099,26 @@ gen_dec_imm_1('ANY', _Constraint, 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};
+ case NNL of
+ [] ->
+ case asn1ct:get_bit_string_format() of
+ compact ->
+ gen_dec_bit_string(decode_compact_bit_string,
+ Imm);
+ legacy ->
+ gen_dec_bit_string(decode_legacy_bit_string,
+ Imm);
+ bitstring ->
+ gen_dec_copy_bitstring(Imm)
+ end;
+ [_|_] ->
+ D = fun(V, Buf) ->
+ As = [V,{asis,NNL}],
+ Call = {call,per_common,decode_named_bit_string,As},
+ emit(["{",Call,com,Buf,"}"])
+ end,
+ {call,D,Imm}
+ end;
gen_dec_imm_1('BOOLEAN', _Constr, _Aligned) ->
asn1ct_imm:per_dec_boolean();
gen_dec_imm_1({'ENUMERATED',{Base,Ext}}, _Constr, Aligned) ->
@@ -1138,6 +1139,18 @@ gen_dec_imm_1('REAL', _Constraint, Aligned) ->
asn1ct_imm:per_dec_real(Aligned);
gen_dec_imm_1(_, _, _) -> no.
+gen_dec_bit_string(F, Imm) ->
+ D = fun(V, Buf) ->
+ emit(["{",{call,per_common,F,[V]},com,Buf,"}"])
+ end,
+ {call,D,Imm}.
+
+gen_dec_copy_bitstring(Imm) ->
+ D = fun(V, Buf) ->
+ emit(["{list_to_bitstring([",V,"]),",Buf,"}"])
+ end,
+ {call,D,Imm}.
+
gen_dec_prim(Erule, Type, BytesVar) ->
case gen_dec_imm(Erule, Type) of
no ->