See embedded comments below<br><br><div class="gmail_quote">On Mon, Dec 10, 2012 at 11:37 AM, Bohuslav Svancara <span dir="ltr"><<a href="mailto:bsvancara@gmail.com" target="_blank">bsvancara@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello!<br><br>I have some problem with ASN1.<br><br>- I have this ASN1 definition in the Test.asn file:<br><br>Test DEFINITIONS IMPLICIT TAGS ::=<br>
<br>BEGIN<br>EXPORTS Test;<br><br>Test ::= SEQUENCE<br>{<br>   a INTEGER,<br>


   b INTEGER DEFAULT 0<br>}<br> <br>END<br><br>- I am using this comand: <br><br>erl -eval asn1ct:compile(\"Test.asn\").<br></blockquote><div><br></div><div>Recommended way to invoke the ASN.1 compiler is</div>
<div>erlc Test.asn # this is equivalent to what you did above.</div><div><br></div><div>This will generate code for BER encoding rules with input/output as a list och integers 0..255</div><div><br></div><div>The most modern and fastest BER backend is invoked like this:</div>
<div>erlc -bber_bin +driver Test.asn </div><div><br></div><div>This will generate code for BER encoding rules with input/output as binaries </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It works fine.<br><br>But when I add a "DEFAULT 0" clause to the line "a INTEGER," so it looks like this:<br>


<br>   a INTEGER DEFAULT 0,<br><br>then asn1ct fails:<br><br>1> asn1error:7:'Test':'Test'<br>{asn1,{duplicates_of_the_tags,[{'UNIVERSAL','INTEGER'}]}}<br>1><br><br>Why please?<br><br>


- Release of Erlang 5.9/OTP R15B <br>- Windows 7 Prof 64-bit<br><br>
Sincerely,<br>Bob<br><br>----------------------------------------------------<br>Just for recap: Failing Test.asn looks like this:<br><br>Test DEFINITIONS IMPLICIT TAGS ::=<br><br>BEGIN<br>EXPORTS Test;<br><br>Test ::= SEQUENCE<br>



{<br>   a INTEGER DEFAULT 0,<br>   b INTEGER DEFAULT 0<br>}<br> <br>END<br><br></blockquote><div><br></div><div>The DEFAULT property on a component in a  SEQUENCE makes that property</div><div>optional , meaning that it can be omitted by the sender.</div>
<div><br></div><div>Since the BER encoding rules are used and the module default is IMPLICIT TAGS</div><div>the tags for the components in a SEQUENCE must be unique (if there are 2 or more optionals in a row). In this case , since no tags are introduced in the syntax the </div>
<div>tags for both a and b component will be UNIVERSAL, INTEGER and the 2 components can not be distinguished from each other. That's why the compiler reports an error.</div><div><br></div><div>In order to correct this you can either change module default to AUTOMATIC TAGS or</div>
<div>add you own tags into the declaration like this:</div><div><br></div><div>Test ::= SEQUENCE<br>{<br>   a [0] INTEGER DEFAULT 0,<br>   b [1] INTEGER DEFAULT 0<br>}<br> </div><div>Now you have two context specific unique tags 0 and 1 for the components which will make it possible to distinguish as a receiver which component (or both) that are</div>
<div>part of the message.</div><div><br></div><div>This is how ASN.1 works , it is not specific to the ASN.1 compiler in OTP</div><div><br></div><div><br></div><div>/Kenneth, Erlang/OTP, Ericsson</div></div>