Menu

Decoder

Andrew Forsyth

JBerd Decoder

Overview

JBerd provides Java facilities for writing programs that use decoded BER data.

Both the Profiler and the Flattener are built using the basic Jberd decoder which is a Java utility class that can easily be put to use within another Java program to enable new BER-consuming programs to be written.

JBerd uses the callback pattern. It takes as an argument a handler object. It then reads an input stream of bytes and interprets it as a BER encoded data stream. At key points in the data stream it calls methods on the handler object to tell the handler about what it has found on the input stream. These key points are:

  • When a new constructed data structure is encountered (i.e. the start of a composite data structure built of other data structures)
  • When the end of a constructed data structure is reached
  • When a primitive data structure is encountered. (i.e an atomic data element with a value).

Handler

To use the JBerd facilities an object that implements the JberdHandler interface must be provided. The interface is as follows.

public interface JberdHandler {

    public void startStruct(JBerdNode n);

    public void endStruct(JBerdNode n);

    public void val(JBerdNode n, byte[] payload);

}

STARTSTRUCT AND ENDSTRUCT

These two methods are called at the start and end of each constructed data structure. JBerd passes a JBerdNode object which provides information about the structure. From this you can know the structure’s tag, and its overall tag path.

So the implemented handler is told about the start and end of each constructed object, what its tag is and where it sits in the hierarchy of all data objects in this BER data stream.

VAL

This method is called after a primitive data structure has been read from the input stream.
Like StartStruct and EndStruct a JBerdNode is provided to inform the called object of where the data object sits in the data type hierarchy of the overall data stream. In addition to this the actual data value that has just been read from the data stream is passed in the form of a byte array.

Further Information

For full documentation, including code for a simple example BER decoder program, see Jberd.pdf

For Java documentation of the JBerd utility classes see Javadoc


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.