CDR with multiple records

335 views
Skip to first unread message

Cherfi Mehdi

unread,
Aug 22, 2013, 11:08:18 AM8/22/13
to asn1-develo...@googlegroups.com
Hi,

I've a CDR with multiple records inside it (attached asn.1 schema and CDR sample(remove the .png from this one)), when I compiled the java files and run the below example:

Vector<ChargingDataOutputRecord> l = CCNRecords.ber_decode(new FileInputStream(new File("file")));
l.get(0).print(System.out);

it gives me org.asnlab.asndt.runtime.error.InvalidTagException in the first line, 

any help is more than welcome.

BR 
ccn5_5_1-1-correct.asn1
file.png

Zhiren Hu

unread,
Aug 22, 2013, 11:39:50 AM8/22/13
to asn1-develo...@googlegroups.com
Hi,

I can't find the CCNRecords type in ASN.1 specification, where is this type from? can you send us the program?

In study of the binary data file, it looks like it is in the format of :

<ASN.1 encoding of CDMACallDataRecord> <some number of zeros> <ASN.1 encoding of CDMACallDataRecord>  <some number of zeros>  ...



So i think you should decode the buffer and then skip the zeros bytes, then decode the buffer again until the buffer is empty.



Regards,
Zhiren Hu
huzh...@gmail.com

--
You received this message because you are subscribed to the Google Groups "ASN.1 Development Tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to asn1-development-...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
<ccn5_5_1-1-correct.asn1><file.png>

Zhiren Hu

unread,
Aug 22, 2013, 12:01:50 PM8/22/13
to asn1-develo...@googlegroups.com, Cherfi Mehdi
Hi,

I can't find the CCNRecords type in ASN.1 specification, where is this type from? can you send us the program?

In study of the binary data file, it looks like it is in the format of :

<ASN.1 encoding of CDMACallDataRecord> <some number of zeros> <ASN.1 encoding of CDMACallDataRecord>  <some number of zeros>  ...



So i think you should decode the buffer and then skip the zeros bytes, then decode the buffer again until the buffer is empty.



Regards,
Zhiren Hu
huzh...@gmail.com

Le 22 août 2013 à 23:08, Cherfi Mehdi a écrit :

Cherfi Mehdi

unread,
Aug 22, 2013, 12:04:50 PM8/22/13
to Zhiren Hu, asn1-develo...@googlegroups.com
sorry for that, when I couldn't solve the issue I added that type myself to the schema as follow:

CCNRecords ::= SEQUENCE OF ChargingDataOutputRecord

you can ignore it.

is there any tutorial on how to do what you suggest ?

BR


2013/8/22 Zhiren Hu <huzh...@gmail.com>

Zhiren Hu

unread,
Aug 22, 2013, 12:20:12 PM8/22/13
to Cherfi Mehdi, asn1-develo...@googlegroups.com
Hi,

The binary data file is not in SEQUENCE OF ChargingDataOutputRecord format, so the CCNRecords type is useless.

try something like this:

                byte[] content = ... // read from file
ByteBuffer buffer = (ByteBuffer) Buffer.wrap(content, EncodingRules.BASIC_ENCODING_RULES);

try {
while (buffer.hasRemaining()) {
ChargingDataOutputRecord cdor = (ChargingDataOutputRecord) ChargingDataOutputRecord.TYPE.decode(buffer, ChargingDataOutputRecord.CONVERTER);
ChargingDataOutputRecord.TYPE.print(cdor, ChargingDataOutputRecord.CONVERTER, System.out).println();

if (buffer.hasRemaining()) {
byte b = buffer.getByte();
while (b == 0 && buffer.hasRemaining()) {
b = buffer.getByte();
}
if (b != 0) {
buffer.position(buffer.position() - 1);
}
}

}
} catch (Exception e) {
e.printStackTrace();
System.out.println(buffer.remaining());
}
}

}


Regards,
Zhiren Hu
huzh...@gmail.com

Cherfi Mehdi

unread,
Aug 22, 2013, 1:20:21 PM8/22/13
to Zhiren Hu, asn1-develo...@googlegroups.com
thanks for helping, but this still didn't solve my problem, still getting

Exception in thread "main" org.asnlab.asndt.runtime.error.InvalidTagException
    at org.asnlab.asndt.runtime.type.SequenceType.D(yb:39)
    at org.asnlab.asndt.runtime.type.SequenceType.D(yb:74)
    at org.asnlab.asndt.runtime.type.AsnType.D(ib:322)
    at org.asnlab.asndt.runtime.type.ListType.D(eb:52)
    at org.asnlab.asndt.runtime.type.ImplicitType.D(cc:70)
    at org.asnlab.asndt.runtime.type.SequenceType.D(yb:181)
    at org.asnlab.asndt.runtime.type.SequenceType.D(yb:74)
    at org.asnlab.asndt.runtime.type.ImplicitType.D(cc:70)
    at org.asnlab.asndt.runtime.type.SequenceType.D(yb:181)
    at org.asnlab.asndt.runtime.type.SequenceType.D(yb:74)
    at org.asnlab.asndt.runtime.type.ImplicitType.D(cc:70)
    at org.asnlab.asndt.runtime.type.ChoiceType.D(yc:100)
    at org.asnlab.asndt.runtime.type.AsnType.D(ib:322)
    at org.asnlab.asndt.runtime.type.ListType.D(eb:52)
    at org.asnlab.asndt.runtime.type.ImplicitType.D(cc:70)
    at org.asnlab.asndt.runtime.type.SequenceType.D(yb:181)
    at org.asnlab.asndt.runtime.type.SequenceType.D(yb:74)
    at org.asnlab.asndt.runtime.type.ImplicitType.D(cc:70)
    at org.asnlab.asndt.runtime.type.ChoiceType.D(yc:100)
    at org.asnlab.asndt.runtime.type.AsnType.D(ib:322)
    at org.asnlab.asndt.runtime.type.ByteBuffer.decode(pc:202)
    at org.asnlab.asndt.runtime.type.AsnType.decode(ib:424)
    at CDRCCN.CDRCCN.main(CDRCCN.java:63)

below is the code I used:
/*
 * Generated by ASN.1 Java Compiler (http://www.asnlab.org/)
 * From ASN.1 module "CDRCCN"
 */
package CDRCCN;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Vector;

import org.apache.commons.io.FileUtils;
import org.asnlab.asndt.runtime.conv.AsnConverter;
import org.asnlab.asndt.runtime.conv.EncodingRules;
import org.asnlab.asndt.runtime.type.AsnModule;
import org.asnlab.asndt.runtime.type.AsnType;
import org.asnlab.asndt.runtime.type.Buffer;
import org.asnlab.asndt.runtime.type.ByteBuffer;


public class CDRCCN extends AsnModule {

    public final static CDRCCN instance = new CDRCCN();


    /**
    /* Creates the ASN.1 module.
    /* The ASN.1 module instance is created automatically, clients must not call.
    /* A metadata file named CDRCCN.meta must exist in the same package of this class.
     **/
    private CDRCCN() {
        super(CDRCCN.class);
    }


    public static AsnType type(int id) {
        return instance.getType(id);
    }

    public static Object value(int valueId, AsnConverter converter) {
        return instance.getValue(valueId, converter);
    }

    public static Object object(int objectId, AsnConverter converter) {
        return instance.getObject(objectId, converter);
    }

    public static Vector objectSet(int objectSetId, AsnConverter converter) {
        return instance.getObjectSet(objectSetId, converter);
    }

    /**
     * Sample test code
     */
    public static void main(String[] args) {
try {
           
            ByteBuffer buffer = (ByteBuffer) Buffer.wrap(FileUtils.readFileToByteArray(new File("D:\\Downloads\\tmp\\CDRS\\CCNCDR44-Blk32768Blk-03-130822-1531-1854")), EncodingRules.BASIC_ENCODING_RULES);

            while (buffer.hasRemaining()) {
               
               
               
                ChargingDataOutputRecord cdor = (ChargingDataOutputRecord) ChargingDataOutputRecord.TYPE.decode(buffer, ChargingDataOutputRecord.CONVERTER);
                ChargingDataOutputRecord.TYPE.print(cdor, ChargingDataOutputRecord.CONVERTER, System.out).println();

                if (buffer.hasRemaining()) {
                    byte b = buffer.getByte();
                    while (b == 0 && buffer.hasRemaining()) {
                    b = buffer.getByte();
                    }
                    if (b != 0) {
                    buffer.position(buffer.position() - 1);
                    }
                }

                }
           
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }


    private static <V> void test(V value, AsnType type, AsnConverter converter) {
        System.out.println("======== print ========");
        type.print(value, converter, System.out);
        System.out.println();
        System.out.println();

        System.out.println("======== encode ========");
        Buffer buffer = Buffer.allocate(1024, EncodingRules.BASIC_ENCODING_RULES);
        type.encode(value, buffer, converter);
        byte[] bytes = buffer.array();
        for(byte b : bytes) {
            System.out.printf("%02X ", b & 0xFF);
        }
        System.out.println();
        System.out.println();

        System.out.println("======== decode ========");
        Buffer buffer2 = Buffer.wrap(bytes, EncodingRules.BASIC_ENCODING_RULES);
        V newValue = (V) type.decode(buffer2, converter);
        type.print(newValue, converter, System.out);
        System.out.println();
        System.out.println();

        System.out.println("======== equality ========");
        System.out.println(type.equals(value, newValue, converter));
    }

}

Cherfi Mehdi

unread,
Aug 23, 2013, 7:03:20 AM8/23/13
to Zhiren Hu, asn1-develo...@googlegroups.com
Hi Zhiren,

it seems the ASN schema was wrong, I was able to decode the CDR with the attached schema, but still I'm only able to get the first record in the file with this code :

        InputStream is = new FileInputStream(new File("file.png"));
        ChargingDataOutputRecord cdr = ChargingDataOutputRecord.ber_decode(is);
        cdr.print(new PrintStream(new FileOutputStream(new File("cdr_decoded.txt"), true)));

if I try to decode a second time I get an InvalidTagException. any ideas on how to decode all the records in one file ?

thanks again.


2013/8/22 Cherfi Mehdi <che...@gmail.com>
ccncdr44.asn1
sdpdatarecord.asn1

Zhiren Hu

unread,
Aug 23, 2013, 7:55:45 AM8/23/13
to Cherfi Mehdi, asn1-develo...@googlegroups.com
Hi,

As I said earlier, the binary data has zeros between PDUs, so try to skip these zeros before decode again:

ByteBuffer buffer = (ByteBuffer) Buffer.wrap(
FileUtils.readFileToByteArray(new File("file")),
EncodingRules.BASIC_ENCODING_RULES);

while (buffer.hasRemaining()) {

ChargingDataOutputRecord cdor = (ChargingDataOutputRecord) ChargingDataOutputRecord.TYPE
.decode(buffer, ChargingDataOutputRecord.CONVERTER);
ChargingDataOutputRecord.TYPE.print(cdor,
ChargingDataOutputRecord.CONVERTER, System.out)
.println();

if (buffer.hasRemaining()) {
byte b = buffer.getByte();
while (b == 0 && buffer.hasRemaining()) {
b = buffer.getByte();
}
if (b != 0) {
buffer.position(buffer.position() - 1);
}
}

}


System.out.println(buffer.remaining()+"/"+buffer.limit());


The last output is  0/16384 which means the buffer is empty after decoding.



Regards,
Zhiren Hu
huzh...@gmail.com

<ccncdr44.asn1><sdpdatarecord.asn1>

Cherfi Mehdi

unread,
Aug 23, 2013, 6:29:20 PM8/23/13
to Zhiren Hu, asn1-develo...@googlegroups.com
working like a charm now, thanks a lot for your help

PS: why isn't your tool listed here ? I believe it should,

BR


2013/8/23 Zhiren Hu <huzh...@gmail.com>
Reply all
Reply to author
Forward
0 new messages