0

我尝试解码 CDR 文件以将其转换为 XML

我已经在我的 PC 上安装了 Java 编译器。我使用了这个链接http://www.asnlab.org/asndt/overview.html

我试图解码我的 CDR 文件,但它不能正常工作。

它正确显示了前 19 条记录,然后它给了我错误,我尝试了 2 个不同的 CDR 文件。而且它们都只显示了 19 条记录。

第一个文件给了我这个错误:

记录 20 org.asnlab.asndt.runtime.error.AsnRuntimeException: Can not invoke method 'valueOf()' 794995 at org.asnlab.asndt.runtime.conv.ReflectionEnumeratedConverter.toObject(ed:40) at org.asnlab.asndt。 runtime.type.EnumeratedType.I(mc:126) at org.asnlab.asndt.runtime.type.ImplicitType.I(xc:152) at org.asnlab.asndt.runtime.type.SetType.I(gb:191)在 org.asnlab.asndt.runtime.type.SetType.I(gb:158) 在 org.asnlab.asndt.runtime.type.ImplicitType.I(xc:152) 在 org.asnlab.asndt.runtime.type.ChoiceType .I(hc:183) 在 org.asnlab.asndt.runtime.type.SequenceType.I(xb:221) 在 org.asnlab.asndt.runtime.type.SequenceType.I(xb:46) 在 org.asnlab。 asndt.runtime.type.ImplicitType.I(xc:152) at org.asnlab.asndt.runtime.type.AsnType.I(bb:354) at org.asnlab.asndt.runtime.type.ByteBuffer.decode(fc: 18) 在 org.asnlab.asndt.runtime.type。AsnType.decode(bb:338) 在 Test.main(Test.java:20)

第二个文件给了我这个错误:

在 org.asnlab.asndt.runtime.type.AsnType.I(bb:369) 在 org.asnlab.asndt.runtime.type.ByteBuffer.decode(fc: 18) 在 org.asnlab.asndt.runtime.type.AsnType.decode(bb:338) 在 Test.main(Test.java:20)

我不明白我的 ASN.1 定义是否有问题?

4

2 回答 2

0

CDR 文件并非完全采用 ASN.1 编码格式,记录之间存在空格 (ASCII 32)。一种解决方法是在每次解码记录时检测并过滤掉这些空间,就像这里的代码示例:

        byte[] content = FileUtils.readFileToByteArray(new File("CDR1"));
        ByteBuffer 缓冲区 = (ByteBuffer) Buffer.wrap(content, EncodingRules.BASIC_ENCODING_RULES);

        CDMACallDataRecords 记录 = 新的 CDMACallDataRecords();
        尝试 {
            而(缓冲区。hasRemaining()){
                CDMACallDataRecord ccdr = (CDMACallDataRecord) CDMACallDataRecord.TYPE.decode(buffer, CDMACallDataRecord.CONVERTER);
                记录.记录.添加(ccdr);

                if (buffer.hasRemaining()) {
                    字节 b = buffer.getByte();
                    while (b == 32 && buffer.hasRemaining()) {
                        b = buffer.getByte();
                    }
                    如果(b!= 32){
                        buffer.position(buffer.position() - 1);
                    }
                }

            }
        } 捕捉(异常 e){
            e.printStackTrace();
            System.out.println(buffer.remaining());
        }

此错误未指定给 ASN.1 编码,因此与 ASN.1 工具无关。

于 2013-10-16T14:28:48.427 回答
0

最好向您正在使用的 ASN.1 工具的供应商询问这个问题。另一种可能性是尝试其他 ASN.1 工具,例如 ITU-T ASN.1 项目页面 ( http://www.itu.int/ITU-T/asn1/links/index.htm ) 中列出的工具之一。还有免费的在线 ASN.1 编译器和编码器/解码器,您可以在http://asn1-playground.oss.com试用。这个免费的在线工具可以为您提供 CDR 的详细分析,让您了解问题所在。

于 2013-07-25T17:14:54.957 回答