Hi Lev, I still don't get it. I guess I was confusing from the beginning because the real problem is not when I encode the object, but when I decode it. Since I wrote both ends of the communication channel, I need to understand the encoding procedure in order to be able to write a correct decoding function. Back to my original question: On the encoding side, the choice member has the milliseconds field as the chosen value and the field is set to 0. According to you, the time-SecondFractions field should be skipped altogether. How can I figure out on the decoding side which value was the chosen one since there is nothing encoded?
All the best, Eddie PS: You were right, BER doesn't impose to skip the OPTIONAL or DEFAULT value. I am trying to write a general procedure for decoding, so I need to deal with both cases. If the OPTIONAL or the DEFAULT value are explicitly encoded, the decoding algorithm will find and decode the fields. If the encoding entity decides to skip them (being allowed to do so by the BER standard), the decoding end must have means of figuring out which one is missing, why is it missing and what value should assign to the missing fields. -----Original Message----- From: Lev Walkin [mailto:[EMAIL PROTECTED] Sent: Thursday, May 12, 2005 1:30 PM To: Eduard Lascu Cc: [email protected] Subject: Re: [ASN1] BER encoding of a CHOICE type that has data members with DEFAULT value Eduard Lascu wrote: > Hello ASN.1 experts, > > I have a CHOICE type that is defined like this: > > time-SecondFractions CHOICE { > deci-seconds INTEGER (0..9), > centi-seconds INTEGER (0..99), > milliseconds INTEGER (0..999) ) DEFAULT(0) > > I have a problem interpreting what the BER standard says about encoding such > a field. On one hand, members having the Default value are not to be > encoded. BER does not impose such a requirement. This member may or may not be included, both ways are explicitly allowed. On the other hand, DER and CER actually do have such restriction. > In a SEQUENCE, the class of the members is context specific and the > tag numbers are used too determine which member is present and which is > absent. Do you have "AUTOMATIC TAGS" somewhere in the beginning of your ASN.1 module? If you do, the time-SecondFractions is actually this: time-SecondFractions [???] EXPLICIT CHOICE { deci-seconds [0] IMPLICIT INTEGER (0..9), centi-seconds [1] IMPLICIT INTEGER (0..99), milliseconds [2] IMPLICIT INTEGER (0..999) ) DEFAULT(0) so all tags are distinct and there's no confusion of what happens if you don't encode time-SecondFractions. > On the other hand, BER says that the encoding of a choice value shall be the > same as the encoding of the value of the chosen type. If the inner members > are not OPTIONAL and cannot have a DEFAULT VALUE everything is fine. But if > they are OPTIONAL or if they can have a DEFAULT VALUE (such as my case, > above described) I am confused. > > If my chosen type has exactly the default value, how do I encode the Choice? You should skip that time-SecondFractions field altogether. -- Lev Walkin [EMAIL PROTECTED] _______________________________________________ ASN1 mailing list [email protected] http://lists.asn1.org/mailman/listinfo/asn1
