python asn1tools - asn.1 编译失败

python asn1tools - failing compilation of asn.1

我正在尝试编译 3GPP 38.331 ASN.1 规范 here - which was extracted from the spec document

import asn1tools
rrc = asn1tools.compile_files('./data/asn/38331-f80.docx.asn', 'uper')

但是这会引发错误 asn1tools.errors.CompileError: Type 'SetupRelease' not found in module 'NR-RRC-Definitions'.

我可以在 .asn 文件中看到 SetupRelease 定义

SetupRelease { ElementTypeParam } ::= CHOICE {
    release         NULL,
    setup           ElementTypeParam
}

很可能你的编译器不支持参数化类型。

您可以用不同的方式编写规范(保持兼容)

考虑从您的规范中删除它...

SetupRelease { ElementTypeParam } ::= CHOICE {
    release         NULL,
    setup           ElementTypeParam
}

每次在规范中引用此类型时,将 ElementTypeParam 替换为实际类型。

例如...

LocationMeasurementIndication-IEs ::=       SEQUENCE {
    measurementIndication                       SetupRelease {LocationMeasurementInfo},
    lateNonCriticalExtension                    OCTET STRING                                                            OPTIONAL,
    nonCriticalExtension                        SEQUENCE{}                                                              OPTIONAL
}

应该变成

LocationMeasurementIndication-IEs ::=       SEQUENCE {
    measurementIndication  CHOICE {
        release         NULL,
        setup           LocationMeasurementInfo
    },
    lateNonCriticalExtension   OCTET STRING   OPTIONAL,
    nonCriticalExtension    SEQUENCE{}        OPTIONAL
}