[erlang-questions] Decoding of ASN.1 BER files
Anders Nygren
anders.nygren@REDACTED
Sun Sep 30 15:26:38 CEST 2007
On 9/29/07, Bruce Fitzsimons <Bruce@REDACTED> wrote:
> Hullo list,
>
> A hint and a request.
>
> The hint: If you need to process files of ASN.1 structures concatenated
> together then the standard routines generated by the asn1ct module will
> almost work perfectly (proven for BER at least), you only need to alter
> the <toplevel>:decode/2 to return the remaining bytes and length from
> whatever reasonable size chunk of binary data you pass in (they default
> to suppressing it). Concatenate, rinse, repeat. A simple fix, but like
> most simple fixes they take more investigation than the ugly hack that
> went before them...
>
> The request: It would be nice if the asn1ct generated <ASN1_erl>:decode
> functions returned this information by default, or via an alternative
> entry point. I can understand the encode routines accepting exactly the
> required amount of data, but for decodes having the correct information
> only occurs in some circumstances such as TCAP packet decoding (and even
> there it is of interest to know if there are leftovers).
>
> If there is interest and /// motivation I can produce a patch to provide
> this behaviour, or otherwise if someone can tell me the rationale for
> not providing it and how else I should parse files I'd be interested.
>
> For those still reading I am constructing a webpage for 3GPP CDR
> decoding (MSC, SGSN, IMS, LBS etc). Someone at work described how their
> hand-coded BER decoder crashed when extra fields were added (!) the
> other day and that offended me to the point of getting the 3GPP ASN.1
> source for CDRs compiling under Erlang (non-trivial dependencies). I'll
> post the url when the rest is working.
>
Hi
It seems like the asn1 compiler option does most of what You want.
>From the docs
"undec_rest
A buffer that holds a message, beeing decoded may also have some
following bytes.
Now it is possible to get those following bytes returned together with
the decoded value.
If an asn1 spec is compiled with this option a tuple {ok,Value,Rest}
is returned.
Rest may be a list or a binary. Earlier versions of the compiler
ignored those following
bytes. "
/Anders
More information about the erlang-questions
mailing list