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

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
protected  int lastCipher
           
protected  java.lang.String lastSymbol
           
 
Fields inherited from class com.devexperts.qd.qtp.AbstractByteArrayParser
in, limit, processed, readAs, 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
protected  void doAfterMessageBody(int messageType)
           
protected  void doAfterMessageHeader()
           
protected  void doBeforeMessage()
           
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.
protected  void readRecordData(RecordReader rr, RecordBuffer buffer, int cipher, java.lang.String symbol)
           
protected  int readRecordId()
           
protected  long readSubscriptionTime()
           
protected  boolean readSymbol()
           
 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, readAs, removeBytes, replaceReadType, resetBuffer, setLimit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lastCipher

protected int lastCipher

lastSymbol

protected java.lang.String lastSymbol
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.

Overrides:
resetSession in class AbstractByteArrayParser
Throws:
java.lang.UnsupportedOperationException - when parser was constructed without describe records mode.

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.

readSymbol

protected boolean readSymbol()
                      throws java.io.IOException
Throws:
java.io.IOException

readRecordId

protected int readRecordId()
                    throws java.io.IOException
Throws:
java.io.IOException

readRecordData

protected void readRecordData(RecordReader rr,
                              RecordBuffer buffer,
                              int cipher,
                              java.lang.String symbol)
                       throws java.io.IOException
Throws:
java.io.IOException

readSubscriptionTime

protected long readSubscriptionTime()
                             throws java.io.IOException
Throws:
java.io.IOException

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

doBeforeMessage

protected void doBeforeMessage()

doAfterMessageHeader

protected void doAfterMessageHeader()

doAfterMessageBody

protected void doAfterMessageBody(int messageType)