Decoding Multiple CDR Records from a File

While writing Call Data Records (CDR) files, telephone equipment vendors often add proprietary information. Typically, you can see the vendor-specific bytes by converting the file to HEX format. In the following example, the CDR records are stored in blocks of 1024 bytes. For each block, the first four bytes hold the proprietary header, the next bytes hold the CDR record (the ASN.1 BER-encoded part will be decoded), followed by trailing bytes until the next block is reached.

Example

The following sample code illustrates two alternative ways of decoding multiple CDRs:

// The CDR object and the BER decoder object
Proj.BerCodec codec = new Proj.BerCodec(); 
Proj.CDR.CallEventRecord rec = new Proj.CDR.CallEventRecord();

// File format:
// 0  1  2  3  4                ...                 1024 
// | header   |   CDR record   |   trailing bytes    | next block ...
// xx xx xx xx XX XX XX ... XX 00 00 00 00 ... 00 00 

const int blockLength = 1024; 
const int headerLength = 4; 
byte[] buffer = new byte[blockLength]; 
int recLength = 0; 

// Read in blocks of 1024 bytes from the file into a buffer
// Decode the buffer by skipping 4 bytes of the proprietary header 
using (System.IO.Stream fs = System.IO.File.OpenRead("cdr.ber")) 
  while (fs.Read(buffer, 0, buffer.Length) > 0) 
  { 
    recLength = codec.Decode(buffer, headerLength, rec);  
    System.Console.WriteLine("Record length {0}: {1}", recLength, rec); 
  }

// Alternative way to decode directly from the file by skipping trailing 00s  
using (System.IO.Stream fs = System.IO.File.OpenRead("cdr.ber"))
  while (fs.Read  while (fs.Read(buffer, 0, headerLength) > 0) // Skip the header 
  { 
    recLength = codec.Decode(fs, rec); 
    System.Console.WriteLine("Record length {0}: {1}", recLength, rec);
    // Skip trailing 00s 
    int b = 0; 
    while (b == 0) 
      b = fs.ReadByte(); 
    if (b > 0) // Non-zero byte - next block/record 
      fs.Seek(-1, System.IO.SeekOrigin.Current); // Roll back one byte
    else 
      break; //EOF 
  }

Download files for this article. Note that you must first compile the .asn file to use the generated files with the Program.cs file.

Tags:

C# | Multiple CDR | BER | Decoding


The samples included with some of the Knowledge Center answers are meant for your general understanding of the OSS products. Different versions of the products might produce slightly different outputs. Consult the products documentation and samples for the most up-to-date products information and code examples.



Contact Support
contact Our office hours
24 hours/day, 7 days/week

  • Phone: 1-888-OSS-2761 (USA and Canada)
  • Phone: 1-732-302-9669 (International)
  • Fax: 1-732-302-0023
  • Email: support@oss.com
Free Trial
download

Test drive the OSS Nokalva ASN.1, LTE, and XML Tools now! Your trial includes complete software, documentation, sample programs, free 24x7 technical support and more.




Learn ASN.1
Learn ASN.1

Our expert personnel can help you learn ASN.1!

We offer 4-day ASN.1 courses at our headquarters or your premises.