ASN.1 multiple records with multiple record definitions

Lars Thorsen lars.thorsen@REDACTED
Tue Jun 30 14:52:59 CEST 2020

Here comes a solution for your problem (not using SEQUENCE OF).
Compile your spec with the option undec_rest.

asn1ct:compile("People.asn1", [undec_rest]).

Then do a decode function in your module.

decode(<<>>, Acc) ->
decode(Data, Acc) ->
    {ok, P, Rest} = 'People':decode('RecordType', Data),
    decode(Rest, [P | Acc]).

1> {ok, Txt} = file:read_file("cdr.dat").
2> YourModule:decode(Data, []).
[{person,{'Person',"John Smith",5,38}},
 {contact,{'Contact',"Vanessa","123 456"}},
 {contact,{'Contact',"Alicia","987 654"}}]

Best Regards Lars

-----Original Message-----
From: erlang-questions <erlang-questions-bounces@REDACTED> On Behalf Of Papa Tana
Sent: den 30 juni 2020 14:23
To: erlang-questions@REDACTED
Subject: Re: ASN.1 multiple records with multiple record definitions

This project is SOLVED!!
Let me share here the solution provided by some OTP team in my inbox.

===> SOLUTION: need to specify that there will be a sequence of RecordType.

%% update People.asn
List ::= SEQUENCE OF RecordType

%% insert Data in the CDR-people.dat
{ok, Binx} =
                         [{person, {'Person', "John Smith", 5, 38}},
                          {contact, {'Contact', "Vanessa", "123 456"}},
                          {contact, {'Contact', "Alicia", "987 654"}},
                          {person, {'Person', "Mercator", 0, 32}}]).

file:write_file("CDR-people.dat", Binx).

%% Retrieving all the values is successful {ok, Txt} = file:read_file("CDR-people.dat").
'People':decode('PList', Txt).

But it works at THE ONLY CONDITION that I can change People.asn My project in the real world is that some vendor provides me a non-editable CDR.asn and a list of CDRxxxx.dat files containing different types of record.
Maybe there is some Header as specified by OTP team, or any additional field that I am missing in the Binary result decoding, I will explore this way.

> 2020-06-30 10:13 UTC+03:00, Papa Tana <papa.tana101@REDACTED>:
> But when I'm reading the file, and decode, it only returns the first 
> Person, sounds like the 3 upcoming records are ignored:

More information about the erlang-questions mailing list