Search in sources :

Example 1 with BerObjectDescriptor

use of org.openmuc.jasn1.ber.types.string.BerObjectDescriptor in project jasn1 by openmuc.

the class BerEmbeddedPdv method decode.

public int decode(InputStream is, boolean withTag) throws IOException {
    int codeLength = 0;
    int subCodeLength = 0;
    BerTag berTag = new BerTag();
    if (withTag) {
        codeLength += tag.decodeAndCheck(is);
    }
    BerLength length = new BerLength();
    codeLength += length.decode(is);
    int totalLength = length.val;
    codeLength += totalLength;
    subCodeLength += berTag.decode(is);
    if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
        subCodeLength += length.decode(is);
        identification = new Identification();
        subCodeLength += identification.decode(is, null);
        subCodeLength += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match the mandatory sequence element tag.");
    }
    if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
        dataValueDescriptor = new BerObjectDescriptor();
        subCodeLength += dataValueDescriptor.decode(is, false);
        subCodeLength += berTag.decode(is);
    }
    if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
        dataValue = new BerOctetString();
        subCodeLength += dataValue.decode(is, false);
        if (subCodeLength == totalLength) {
            return codeLength;
        }
    }
    throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
}
Also used : BerLength(org.openmuc.jasn1.ber.BerLength) BerObjectDescriptor(org.openmuc.jasn1.ber.types.string.BerObjectDescriptor) IOException(java.io.IOException) BerTag(org.openmuc.jasn1.ber.BerTag)

Aggregations

IOException (java.io.IOException)1 BerLength (org.openmuc.jasn1.ber.BerLength)1 BerTag (org.openmuc.jasn1.ber.BerTag)1 BerObjectDescriptor (org.openmuc.jasn1.ber.types.string.BerObjectDescriptor)1