com.devexperts.qd.qtp
Class ByteArrayParser

java.lang.Object
  extended by com.devexperts.qd.qtp.AbstractByteArrayParser
      extended by com.devexperts.qd.qtp.ByteArrayParser
All Implemented Interfaces:
SymbolReceiver
Direct Known Subclasses:
ConvertingByteArrayParser

public class ByteArrayParser
extends AbstractByteArrayParser
implements SymbolReceiver

The ByteArrayParser parses QTP messages accumulated in a linear byte array buffer.

See Also:
AbstractByteArrayParser

Nested Class Summary
protected static class ByteArrayParser.CorruptedException
          This exception is thrown to indicate that either message or stream are corrupted (depending on the method).
 
Field Summary
 
Fields inherited from class com.devexperts.qd.qtp.AbstractByteArrayParser
in, limit, processed, recordBuffer, scheme, subscriptionBuffer
 
Constructor Summary
ByteArrayParser(DataScheme scheme)
          Constructs parser with a specified scheme in a stateless mode (describe messages are not being parsed).
ByteArrayParser(DataScheme scheme, boolean parseDescribe)
          Constructs parser with a specified scheme and a describe mode.
 
Method Summary
 ProtocolDescriptor getProtocolDescriptor()
          Returns current ProtocolDescriptor or null if one was never received in this session.
protected  RecordReader getRecordReader(int id)
           
 void parse(MessageConsumer consumer)
          Parses accumulated data and retrieve processed messages to specified MessageConsumer.
protected  int parseType()
          Parses and return message type.
 void receiveSymbol(int cipher, java.lang.String symbol)
          Remembers specified cipher and symbol.
protected  void remapRecord(int id, RecordReader rr)
           
 void resetSession()
          Resets session state for parser with describe mode.
 
Methods inherited from class com.devexperts.qd.qtp.AbstractByteArrayParser
addBytes, ensureCapacity, getBuffer, getLimit, getProcessed, nextMessage, processMessage, processPending, removeBytes, setLimit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteArrayParser

public ByteArrayParser(DataScheme scheme)
Constructs parser with a specified scheme in a stateless mode (describe messages are not being parsed). It is the same as ByteArrayParser(scheme, false).

Parameters:
scheme - data scheme to use.

ByteArrayParser

public ByteArrayParser(DataScheme scheme,
                       boolean parseDescribe)
Constructs parser with a specified scheme and a describe mode.

Parameters:
scheme - data scheme to use.
parseDescribe - If true, then all kinds of describe messages are parsed and this instance keeps that information in its state and it shall not be reused for different communication sessions without resetSession() call. Otherwise, the parser is generally almost stateless.
Method Detail

resetSession

public void resetSession()
Resets session state for parser with describe mode. Resets the state of all parsed describes so far, as if this parser was just created.

Throws:
java.lang.UnsupportedOperationException - when parser was constructed witout describe records mode.

getProtocolDescriptor

public ProtocolDescriptor getProtocolDescriptor()
Returns current ProtocolDescriptor or null if one was never received in this session.


parse

public void parse(MessageConsumer consumer)
Description copied from class: AbstractByteArrayParser
Parses accumulated data and retrieve processed messages to specified MessageConsumer. This is the main method in this class. It doesn't remove parsed bytes from buffer, it only updates processed value.

Specified by:
parse in class AbstractByteArrayParser
Parameters:
consumer - MessageConsumer to pass parsed messages.

parseType

protected int parseType()
                 throws ByteArrayParser.CorruptedException
Parses and return message type.

Throws:
ByteArrayParser.CorruptedException - if stream is corrupted.

remapRecord

protected void remapRecord(int id,
                           RecordReader rr)

getRecordReader

protected RecordReader getRecordReader(int id)

receiveSymbol

public void receiveSymbol(int cipher,
                          java.lang.String symbol)
Description copied from interface: SymbolReceiver
Remembers specified cipher and symbol.

Specified by:
receiveSymbol in interface SymbolReceiver