Search in sources :

Example 1 with AsnTag

use of org.openmuc.jasn1.compiler.model.AsnTag in project jasn1 by openmuc.

the class BerClassWriter method addAutomaticTagsIfNeeded.

private void addAutomaticTagsIfNeeded(List<AsnElementType> componentTypes) throws IOException {
    if (tagDefault != TagDefault.AUTOMATIC) {
        return;
    }
    for (AsnElementType element : componentTypes) {
        if (getTag(element) != null) {
            return;
        }
    }
    int i = 0;
    for (AsnElementType element : componentTypes) {
        element.tag = new AsnTag();
        element.tag.classNumber = new AsnClassNumber();
        element.tag.classNumber.num = i;
        i++;
    }
}
Also used : AsnClassNumber(org.openmuc.jasn1.compiler.model.AsnClassNumber) AsnElementType(org.openmuc.jasn1.compiler.model.AsnElementType) AsnTag(org.openmuc.jasn1.compiler.model.AsnTag)

Example 2 with AsnTag

use of org.openmuc.jasn1.compiler.model.AsnTag in project jasn1 by openmuc.

the class BerClassWriter method getTag.

/**
 * Gets the tag from the AsnTaggedType structure. The returned tag will contain the correct class and type (explicit
 * or implicit). Return null if the passed tagged type does not have a tag.
 *
 * @param asnTaggedType
 * @return the tag from the AsnTaggedType structure
 * @throws IOException
 */
private Tag getTag(AsnTaggedType asnTaggedType) throws IOException {
    AsnTag asnTag = asnTaggedType.tag;
    if (asnTag == null) {
        return null;
    }
    Tag tag = new Tag();
    String tagClassString = asnTag.clazz;
    if (tagClassString.isEmpty() || "CONTEXT".equals(tagClassString)) {
        tag.tagClass = TagClass.CONTEXT;
    } else if ("APPLICATION".equals(tagClassString)) {
        tag.tagClass = TagClass.APPLICATION;
    } else if ("PRIVATE".equals(tagClassString)) {
        tag.tagClass = TagClass.PRIVATE;
    } else if ("UNIVERSAL".equals(tagClassString)) {
        tag.tagClass = TagClass.UNIVERSAL;
    } else {
        throw new IllegalStateException("unknown tag class: " + tagClassString);
    }
    String tagTypeString = asnTaggedType.tagType;
    if (tagTypeString.isEmpty()) {
        if (tagDefault == TagDefault.EXPLICIT) {
            tag.type = TagType.EXPLICIT;
        } else {
            tag.type = TagType.IMPLICIT;
        }
    } else if (tagTypeString.equals("IMPLICIT")) {
        tag.type = TagType.IMPLICIT;
    } else if (tagTypeString.equals("EXPLICIT")) {
        tag.type = TagType.EXPLICIT;
    } else {
        throw new IllegalStateException("unexpected tag type: " + tagTypeString);
    }
    if (tag.type == TagType.IMPLICIT) {
        if (isDirectAnyOrChoice(asnTaggedType)) {
            tag.type = TagType.EXPLICIT;
        }
    }
    if ((tag.type == TagType.IMPLICIT) && isPrimitive(asnTaggedType)) {
        tag.typeStructure = TypeStructure.PRIMITIVE;
    } else {
        tag.typeStructure = TypeStructure.CONSTRUCTED;
    }
    tag.value = asnTaggedType.tag.classNumber.num;
    return tag;
}
Also used : BerTag(org.openmuc.jasn1.ber.BerTag) AsnTag(org.openmuc.jasn1.compiler.model.AsnTag) AsnBitString(org.openmuc.jasn1.compiler.model.AsnBitString) AsnCharacterString(org.openmuc.jasn1.compiler.model.AsnCharacterString) AsnOctetString(org.openmuc.jasn1.compiler.model.AsnOctetString) AsnTag(org.openmuc.jasn1.compiler.model.AsnTag)

Aggregations

AsnTag (org.openmuc.jasn1.compiler.model.AsnTag)2 BerTag (org.openmuc.jasn1.ber.BerTag)1 AsnBitString (org.openmuc.jasn1.compiler.model.AsnBitString)1 AsnCharacterString (org.openmuc.jasn1.compiler.model.AsnCharacterString)1 AsnClassNumber (org.openmuc.jasn1.compiler.model.AsnClassNumber)1 AsnElementType (org.openmuc.jasn1.compiler.model.AsnElementType)1 AsnOctetString (org.openmuc.jasn1.compiler.model.AsnOctetString)1