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++;
}
}
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;
}
Aggregations