encodingcodecasn.1ber

How is choice index encode in UPER when an extension is present


If I have the ASN.1 schema as shown below (I have truncated it to remove useless data) and I want to encode dm200 following the uPER rules, then I get the following encoding.

{
    "messageData":
    {
        "elementIds":
        [
        {
            "dm200":null
        }
        ]
    }
}

0001100000001010101100000000100000000000

From this I get that

000 (first 3 bits) represent the number of elemendIds present which is 1 + 0 = 1

1 (4th bit) represents that extension is used

From the next bit onwards I am unclear about it. I know that the sequence 01010110 (decimal 86) present in the encoded bits represent the value of 200, which is (114+86 = 200). But I don't know what rest of the bits represent and how they come

Messages DEFINITIONS ::=

BEGIN


Message ::= SEQUENCE
    {
    messageData     MessageData
    }
MessageData ::= SEQUENCE
    {
        elementIds      SEQUENCE SIZE (1..7) OF MsgElementId
    }


MsgElementId ::= CHOICE
{
dm0 [0] NULL,
dm1 [1] NULL,
dm2 [2] NULL,
dm3 [3] NULL,
dm4 [4] NULL,
.
.(This portion is truncated for shortening)
.
dm111 [111] NULL,
dm112 [112] NULL,
dm113 [113] NULL,
...,
dm114 [114] NULL,
dm115 [115] NULL,
dm116 [116] NULL,
.
.(This portion is truncated for shortening)
.
dm200 [200] NULL,
dm201 [201] NULL,
dm202 [202] NULL,
dm203 [203] NULL,
dm204 [204] NULL,
dm205 [205] NULL,
dm206 [206] NULL,
dm207 [207] NULL,
dm208 [208] NULL
}   
    
    
        END

Solution

  • You are looking for ITU-T Rec. X.691 | ISO/IEC 8825-2 clause 23.8 which states:

    23.8 If the extension bit is present and the chosen alternative does not lie within the extension root, the choice index of the chosen alternative shall be encoded as a normally small non-negative whole number with "lb" set to 0 and that field shall be appended to the field-list. This shall then be followed by a field-list containing the encoding of the chosen alternative encoded as if it were the value of an open type field as specified in 11.2, completing the procedures of this clause.

    So you have the choice index encoded as small non-negative whole number (telling you which choice alternative was chosen), then you have the contents of that field encoded as an open type (length followed by the UPER encoding of NULL).

    You can give it a try at the ASN.1 playground (noting that I did not try to fill in the extra fields you deleted): https://asn1.io/asn1playground/default.aspx?schema=H4sIAAAAAAAEAHWRP2vDMBDFd4O%2fw40tFGFZsh0CXRorrSCWKU6Wmg6GmCx1F2Ur%2be71s5pEN%2fQG2e93T%2fcHNaP3w2n0VJutdXZvW9fRev2cJmnyYl6tw0%2baNMGGDHXm%2fWDcxqQJzfETPlMw1MN5gKTmroPhciuyeP4thBi%2fxmn8PtujD%2fpqpM5%2bGHqQQlSP1G6p8Sdztd66LONGiaXV5q21aDQ3OU4Z9dknucNu9wQpqZeRzKnPI6moV5HU1Ov4rsRtKRnKgXKGFNC9jhDiL6GR4BULoIKhEqiMh8zmJeaDIQnEVsmwTJYzpIAUQxpIM1QAFQyVQHyICqhiaAW0CihNLvObhJeJT4Rx9S9hqTnFfAIAAA%3d%3d&datatxt=H4sIAAAAAAAEACtLzClNVfBNLS5OTE9VsLKyVajm5cqFcF0SSxIVqlNzUnNT80o8U4oVqhVScg2s%2fEJ9fHSALEM4y8jAAsyura3l5QJBAHTZ%2frBWAAAA&op=H4sIAAAAAAAEAG2OPQ%2bCQAyG%2f0tnFlY29RyJhFP2CoVcUuvlPhIvxv8uqJwOjn36ft2hvg4EVVmADs70QScJeINqRPZUwIa5GaLPt8aLZeqQI33hXvo55GBJjsn%2b8JcMKkAvJRSgMODWCLqUFYr%2bO998p7tMWmJMGkfKZHHM4TV5jxPBZ4aRqY28PM7kYE2qIwczD2%2fUaS15PAFQNR3W%2bwAAAA%3d%3d