diff options
author | Björn Gustavsson <[email protected]> | 2013-01-22 16:48:41 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2013-01-23 15:22:56 +0100 |
commit | dc17110cd88153a74900d71d35df608f5d58c0f3 (patch) | |
tree | cb13a3bdad07d89b98c96c5292b7297efbf6f728 /lib/asn1/src | |
parent | 26182a5c8cf96fa6d255e23a6d4cd0d2c5248a69 (diff) | |
download | otp-dc17110cd88153a74900d71d35df608f5d58c0f3.tar.gz otp-dc17110cd88153a74900d71d35df608f5d58c0f3.tar.bz2 otp-dc17110cd88153a74900d71d35df608f5d58c0f3.zip |
per,uper: Optimize decoding of the remaining string types
Diffstat (limited to 'lib/asn1/src')
-rw-r--r-- | lib/asn1/src/asn1ct_gen_per.erl | 35 | ||||
-rw-r--r-- | lib/asn1/src/asn1ct_imm.erl | 8 | ||||
-rw-r--r-- | lib/asn1/src/asn1rtt_per.erl | 37 | ||||
-rw-r--r-- | lib/asn1/src/asn1rtt_uper.erl | 30 |
4 files changed, 38 insertions, 72 deletions
diff --git a/lib/asn1/src/asn1ct_gen_per.erl b/lib/asn1/src/asn1ct_gen_per.erl index 25b0d46295..ddfa39486a 100644 --- a/lib/asn1/src/asn1ct_gen_per.erl +++ b/lib/asn1/src/asn1ct_gen_per.erl @@ -1151,6 +1151,20 @@ gen_dec_imm_1('OCTET STRING', Constraint, Aligned) -> SzConstr = get_constraint(Constraint, 'SizeConstraint'), Imm = asn1ct_imm:per_dec_octet_string(SzConstr, Aligned), {convert,binary_to_list,Imm}; +gen_dec_imm_1('TeletexString', _Constraint, Aligned) -> + gen_dec_restricted_string(Aligned); +gen_dec_imm_1('T61String', _Constraint, Aligned) -> + gen_dec_restricted_string(Aligned); +gen_dec_imm_1('VideotexString', _Constraint, Aligned) -> + gen_dec_restricted_string(Aligned); +gen_dec_imm_1('GraphicString', _Constraint, Aligned) -> + gen_dec_restricted_string(Aligned); +gen_dec_imm_1('GeneralString', _Constraint, Aligned) -> + gen_dec_restricted_string(Aligned); +gen_dec_imm_1('ObjectDescriptor', _Constraint, Aligned) -> + gen_dec_restricted_string(Aligned); +gen_dec_imm_1('UTF8String', _Constraint, Aligned) -> + asn1ct_imm:per_dec_restricted_string(Aligned); gen_dec_imm_1('REAL', _Constraint, Aligned) -> asn1ct_imm:per_dec_real(Aligned); gen_dec_imm_1(_, _, _) -> no. @@ -1170,6 +1184,10 @@ gen_dec_copy_bitstring(Imm) -> gen_dec_k_m_string(Type, Constraint, Aligned) -> asn1ct_imm:per_dec_k_m_string(Type, Constraint, Aligned). +gen_dec_restricted_string(Aligned) -> + Imm = asn1ct_imm:per_dec_restricted_string(Aligned), + {convert,binary_to_list,Imm}. + gen_dec_prim(Erule, Type, BytesVar) -> case gen_dec_imm(Erule, Type) of no -> @@ -1179,7 +1197,7 @@ gen_dec_prim(Erule, Type, BytesVar) -> end. gen_dec_prim_1(Erule, - #type{def=Typename,constraint=Constraint}=Att, + #type{def=Typename}=Att, BytesVar) -> case Typename of 'NULL' -> @@ -1188,21 +1206,6 @@ gen_dec_prim_1(Erule, call(Erule, decode_object_identifier, [BytesVar]); 'RELATIVE-OID' -> call(Erule, decode_relative_oid, [BytesVar]); - 'ObjectDescriptor' -> - call(Erule, decode_ObjectDescriptor, [BytesVar]); - TString when TString == 'TeletexString'; - TString == 'T61String' -> - call(Erule, decode_TeletexString, - [BytesVar,{asis,Constraint}]); - 'VideotexString' -> - call(Erule, decode_VideotexString, - [BytesVar,{asis,Constraint}]); - 'GraphicString' -> - call(Erule, decode_GraphicString,[BytesVar,{asis,Constraint}]); - 'GeneralString' -> - call(Erule, decode_GeneralString, [BytesVar,{asis,Constraint}]); - 'UTF8String' -> - call(Erule, decode_UTF8String, [BytesVar]); #'ObjectClassFieldType'{} -> case asn1ct_gen:get_inner(Typename) of {fixedtypevaluefield,_,InnerType} -> diff --git a/lib/asn1/src/asn1ct_imm.erl b/lib/asn1/src/asn1ct_imm.erl index fca85fd778..87eadac073 100644 --- a/lib/asn1/src/asn1ct_imm.erl +++ b/lib/asn1/src/asn1ct_imm.erl @@ -23,7 +23,8 @@ per_dec_extension_map/1, per_dec_integer/2,per_dec_k_m_string/3, per_dec_length/3,per_dec_named_integer/3, - per_dec_octet_string/2,per_dec_open_type/1,per_dec_real/1]). + per_dec_octet_string/2,per_dec_open_type/1,per_dec_real/1, + per_dec_restricted_string/1]). -export([optimize_alignment/1,optimize_alignment/2, dec_slim_cg/2,dec_code_gen/2]). -export([effective_constraint/2]). @@ -136,6 +137,11 @@ per_dec_real(Aligned) -> {get_bits,decode_unconstrained_length(true, Aligned), [8,binary,{align,Aligned}]}}. +per_dec_restricted_string(Aligned) -> + DecLen = decode_unconstrained_length(true, Aligned), + {get_bits,DecLen,[8,binary]}. + + %%% %%% Local functions. %%% diff --git a/lib/asn1/src/asn1rtt_per.erl b/lib/asn1/src/asn1rtt_per.erl index bcd74d9da7..2bcf459330 100644 --- a/lib/asn1/src/asn1rtt_per.erl +++ b/lib/asn1/src/asn1rtt_per.erl @@ -30,12 +30,12 @@ encode_relative_oid/1, decode_relative_oid/1, complete/1, encode_open_type/1, - encode_GeneralString/2, decode_GeneralString/2, - encode_GraphicString/2, decode_GraphicString/2, - encode_TeletexString/2, decode_TeletexString/2, - encode_VideotexString/2, decode_VideotexString/2, - encode_ObjectDescriptor/2, decode_ObjectDescriptor/1, - encode_UTF8String/1,decode_UTF8String/1, + encode_GeneralString/2, + encode_GraphicString/2, + encode_TeletexString/2, + encode_VideotexString/2, + encode_ObjectDescriptor/2, + encode_UTF8String/1, encode_octet_string/3, encode_known_multiplier_string/4, octets_to_complete/2]). @@ -866,34 +866,20 @@ encode_known_multiplier_string(SizeC, NumBits, CharOutTab, Val) -> [encode_length(length(Val)),2,Result] end. -decode_restricted_string(Bytes,aligned) -> - {Len,Bytes2} = decode_length(Bytes,undefined), - getoctets_as_list(Bytes2,Len). - encode_GeneralString(_C,Val) -> encode_restricted_string(Val). -decode_GeneralString(Bytes,_C) -> - decode_restricted_string(Bytes,aligned). encode_GraphicString(_C,Val) -> encode_restricted_string(Val). -decode_GraphicString(Bytes,_C) -> - decode_restricted_string(Bytes,aligned). encode_ObjectDescriptor(_C,Val) -> encode_restricted_string(Val). -decode_ObjectDescriptor(Bytes) -> - decode_restricted_string(Bytes,aligned). encode_TeletexString(_C,Val) -> % equivalent with T61String encode_restricted_string(Val). -decode_TeletexString(Bytes,_C) -> - decode_restricted_string(Bytes,aligned). encode_VideotexString(_C,Val) -> encode_restricted_string(Val). -decode_VideotexString(Bytes,_C) -> - decode_restricted_string(Bytes,aligned). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -948,17 +934,6 @@ encode_UTF8String(Val) -> encode_UTF8String(list_to_binary(Val)). -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% decode_UTF8String(Bytes) -> {Utf8Binary,RemainingBytes} -%% Utf8Binary -> <<utf8 encoded binary>> -%% RemainingBytes -> <<buffer>> -decode_UTF8String(Bytes) -> - {Len,Bytes2} = decode_length(Bytes, undefined), - {_Bin,_Bytes3} = getoctets_as_bin(Bytes2, Len). - - - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% encode_object_identifier(Val) -> CompleteList %% encode_object_identifier({Name,Val}) -> CompleteList diff --git a/lib/asn1/src/asn1rtt_uper.erl b/lib/asn1/src/asn1rtt_uper.erl index 92c8d44402..fa4f08363b 100644 --- a/lib/asn1/src/asn1rtt_uper.erl +++ b/lib/asn1/src/asn1rtt_uper.erl @@ -36,16 +36,16 @@ -export([encode_UniversalString/2, encode_PrintableString/2, - encode_GeneralString/2, decode_GeneralString/2, - encode_GraphicString/2, decode_GraphicString/2, - encode_TeletexString/2, decode_TeletexString/2, - encode_VideotexString/2, decode_VideotexString/2, + encode_GeneralString/2, + encode_GraphicString/2, + encode_TeletexString/2, + encode_VideotexString/2, encode_VisibleString/2, - encode_UTF8String/1, decode_UTF8String/1, + encode_UTF8String/1, encode_BMPString/2, encode_IA5String/2, encode_NumericString/2, - encode_ObjectDescriptor/2, decode_ObjectDescriptor/1 + encode_ObjectDescriptor/2 ]). -define('16K',16384). @@ -795,10 +795,6 @@ encode_known_multiplier_string(StringType, C, Val) -> [encode_length(length(Val)),Result] end. -decode_restricted_string(Bytes) -> - {Len,Bytes2} = decode_length(Bytes, undefined), - getoctets_as_list(Bytes2,Len). - encode_NumericString(C,Val) -> encode_known_multiplier_string('NumericString',C,Val). @@ -823,28 +819,18 @@ encode_UniversalString(C,Val) -> encode_GeneralString(_C,Val) -> encode_restricted_string(Val). -decode_GeneralString(Bytes,_C) -> - decode_restricted_string(Bytes). encode_GraphicString(_C,Val) -> encode_restricted_string(Val). -decode_GraphicString(Bytes,_C) -> - decode_restricted_string(Bytes). encode_ObjectDescriptor(_C,Val) -> encode_restricted_string(Val). -decode_ObjectDescriptor(Bytes) -> - decode_restricted_string(Bytes). encode_TeletexString(_C,Val) -> % equivalent with T61String encode_restricted_string(Val). -decode_TeletexString(Bytes,_C) -> - decode_restricted_string(Bytes). encode_VideotexString(_C,Val) -> encode_restricted_string(Val). -decode_VideotexString(Bytes,_C) -> - decode_restricted_string(Bytes). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -983,10 +969,6 @@ encode_UTF8String(Val) -> Bin = list_to_binary(Val), encode_UTF8String(Bin). -decode_UTF8String(Bytes) -> - {Len,Bytes2} = decode_length(Bytes, undefined), - getoctets_as_bin(Bytes2,Len). - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% encode_object_identifier(Val) -> CompleteList |