From d08ea8d67345d5477d0899322ce18fda3557fe01 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 9 Feb 2011 23:13:48 +0100 Subject: [PATCH] use asn1ct/asn1rc in 'ber list' mode, as 'ber binary' mode has bugs When trying to asn1rt:encode() the DialoguePortion in ber_bin mode, we get something like 2> asn1rt:encode('MAP', 'MapSpecificPDUs', {'begin', Msg}). {error,{asn1,{function_clause,[{asn1rt_check,transform_to_EXTERNAL1990, [[<<96,15,128,2,7,128,161,9,6,7,4,0,0,1,0,5,3>>], [asn1_NOVALUE,asn1_NOVALUE,{0,0,17,773,1,1,1},'EXTERNAL']]}, {'MAP',enc_EXTERNAL,2}, {'MAP',enc_MapSpecificPDUs_begin,2}, {'MAP',enc_MapSpecificPDUs,2}, {'MAP',encode,2}, {asn1rt,encode,3}, {erl_eval,do_apply,5}, {shell,exprs,7}]}}} --- rebar.config | 2 +- src/map_codec.erl | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/rebar.config b/rebar.config index 7eb849a..95a74fe 100644 --- a/rebar.config +++ b/rebar.config @@ -1,2 +1,2 @@ {sub_dirs, ["rel"]}. -{asn1_opts, [ber_bin]}. +{asn1_opts, [ber,verbose]}. diff --git a/src/map_codec.erl b/src/map_codec.erl index eb1f814..90d51d3 100644 --- a/src/map_codec.erl +++ b/src/map_codec.erl @@ -72,7 +72,10 @@ encode_addr_string(#party_number{nature_of_addr_ind = NatureIsup, binary_to_list(Bin). parse_tcap_msg(MsgBin) when is_binary(MsgBin) -> - case asn1rt:decode('map', 'MapSpecificPDUs', MsgBin) of + Msg = binary_to_list(MsgBin), + parse_tcap_msg(Msg); +parse_tcap_msg(Msg) when is_list(Msg) -> + case asn1rt:decode('map', 'MapSpecificPDUs', Msg) of {ok, {Type, TcapMsgDec}} -> {Type, TcapMsgDec}; Error -> @@ -80,4 +83,9 @@ parse_tcap_msg(MsgBin) when is_binary(MsgBin) -> end. encode_tcap_msgt(Type, TcapMsgDec) -> - asn1rt:encode('map', Type, TcapMsgDec). + case asn1rt:encode('map', Type, TcapMsgDec) of + {ok, List} -> + list_to_binary(List); + Error -> + Error + end.