uk.co.real_logic.artio.other.decoder_flyweight.NewOrderSingleDecoder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of artio-session-codecs Show documentation
Show all versions of artio-session-codecs Show documentation
High-Performance FIX Gateway
/* Generated Fix Gateway message codec */
package uk.co.real_logic.artio.other.decoder_flyweight;
import org.agrona.AsciiNumberFormatException;
import uk.co.real_logic.artio.dictionary.Generated;
import org.agrona.MutableDirectBuffer;
import org.agrona.AsciiSequenceView;
import static uk.co.real_logic.artio.dictionary.generation.CodecUtil.*;
import static uk.co.real_logic.artio.dictionary.SessionConstants.*;
import uk.co.real_logic.artio.builder.Decoder;
import uk.co.real_logic.artio.other.decoder_flyweight.HeaderDecoder;
import uk.co.real_logic.artio.other.decoder_flyweight.TrailerDecoder;
import uk.co.real_logic.artio.fields.ReadOnlyDecimalFloat;
import uk.co.real_logic.artio.fields.DecimalFloat;
import uk.co.real_logic.artio.util.MutableAsciiBuffer;
import uk.co.real_logic.artio.util.AsciiBuffer;
import uk.co.real_logic.artio.fields.LocalMktDateEncoder;
import uk.co.real_logic.artio.fields.UtcTimestampEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import uk.co.real_logic.artio.dictionary.CharArraySet;
import org.agrona.collections.IntHashSet;
import org.agrona.collections.IntHashSet.IntIterator;
import uk.co.real_logic.artio.EncodingException;
import uk.co.real_logic.artio.dictionary.CharArrayWrapper;
import uk.co.real_logic.artio.builder.Encoder;
import uk.co.real_logic.artio.builder.CommonDecoderImpl;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static uk.co.real_logic.artio.builder.Validation.CODEC_VALIDATION_ENABLED;
import static uk.co.real_logic.artio.builder.RejectUnknownField.CODEC_REJECT_UNKNOWN_FIELD_ENABLED;
import static uk.co.real_logic.artio.builder.RejectUnknownEnumValue.CODEC_REJECT_UNKNOWN_ENUM_VALUE_ENABLED;
import uk.co.real_logic.artio.other.*;
import uk.co.real_logic.artio.other.builder.NewOrderSingleEncoder;
import uk.co.real_logic.artio.other.builder.InstrumentEncoder;
import uk.co.real_logic.artio.other.builder.OrderQtyDataEncoder;
@Generated("uk.co.real_logic.artio")
public class NewOrderSingleDecoder extends CommonDecoderImpl implements InstrumentDecoder, OrderQtyDataDecoder, MessageDecoder
{
public final IntHashSet REQUIRED_FIELDS = new IntHashSet(12);
{
if (CODEC_VALIDATION_ENABLED)
{
REQUIRED_FIELDS.add(Constants.CL_ORD_ID);
REQUIRED_FIELDS.add(Constants.SYMBOL);
REQUIRED_FIELDS.add(Constants.SIDE);
REQUIRED_FIELDS.add(Constants.TRANSACT_TIME);
REQUIRED_FIELDS.add(Constants.ORD_TYPE);
REQUIRED_FIELDS.add(Constants.PRICE);
}
}
private final IntHashSet alreadyVisitedFields = new IntHashSet(14);
private final IntHashSet unknownFields = new IntHashSet(10);
private final IntHashSet missingRequiredFields = new IntHashSet(12);
public boolean validate()
{
if (rejectReason != Decoder.NO_ERROR)
{
return false;
}
final IntIterator missingFieldsIterator = missingRequiredFields.iterator();
final IntIterator unknownFieldsIterator = unknownFields.iterator();
if (CODEC_REJECT_UNKNOWN_FIELD_ENABLED && unknownFieldsIterator.hasNext())
{
invalidTagId = unknownFieldsIterator.nextValue();
rejectReason = Constants.ALL_FIELDS.contains(invalidTagId) ? 2 : 0;
return false;
}
if (!header.validate())
{
invalidTagId = header.invalidTagId();
rejectReason = header.rejectReason();
return false;
}
else if (!trailer.validate())
{
invalidTagId = trailer.invalidTagId();
rejectReason = trailer.rejectReason();
return false;
}
if (missingFieldsIterator.hasNext())
{
invalidTagId = missingFieldsIterator.nextValue();
rejectReason = 1;
return false;
}
if (CODEC_REJECT_UNKNOWN_ENUM_VALUE_ENABLED && !Side.isValid(side()))
{
invalidTagId = 54;
rejectReason = 5;
return false;
}
if (CODEC_REJECT_UNKNOWN_ENUM_VALUE_ENABLED && !OrdType.isValid(ordType()))
{
invalidTagId = 40;
rejectReason = 5;
return false;
}
return true;
}
public static final long MESSAGE_TYPE = 68L;
public static final String MESSAGE_TYPE_AS_STRING = "D";
public static final char[] MESSAGE_TYPE_CHARS = MESSAGE_TYPE_AS_STRING.toCharArray();
public static final byte[] MESSAGE_TYPE_BYTES = MESSAGE_TYPE_AS_STRING.getBytes(US_ASCII);
public final IntHashSet messageFields = new IntHashSet(48);
{
messageFields.add(Constants.BEGIN_STRING);
messageFields.add(Constants.BODY_LENGTH);
messageFields.add(Constants.MSG_TYPE);
messageFields.add(Constants.SENDER_COMP_ID);
messageFields.add(Constants.TARGET_COMP_ID);
messageFields.add(Constants.MSG_SEQ_NUM);
messageFields.add(Constants.SENDER_SUB_ID);
messageFields.add(Constants.SENDER_LOCATION_ID);
messageFields.add(Constants.TARGET_SUB_ID);
messageFields.add(Constants.TARGET_LOCATION_ID);
messageFields.add(Constants.POSS_DUP_FLAG);
messageFields.add(Constants.POSS_RESEND);
messageFields.add(Constants.SENDING_TIME);
messageFields.add(Constants.ORIG_SENDING_TIME);
messageFields.add(Constants.LAST_MSG_SEQ_NUM_PROCESSED);
messageFields.add(Constants.TEST_FIELD);
messageFields.add(Constants.CL_ORD_ID);
messageFields.add(Constants.SYMBOL);
messageFields.add(Constants.SIDE);
messageFields.add(Constants.TRANSACT_TIME);
messageFields.add(Constants.ORDER_QTY);
messageFields.add(Constants.ORD_TYPE);
messageFields.add(Constants.PRICE);
messageFields.add(Constants.CHECK_SUM);
}
private final TrailerDecoder trailer = new TrailerDecoder();
public TrailerDecoder trailer()
{
return trailer;
}
private final HeaderDecoder header = new HeaderDecoder(trailer);
public HeaderDecoder header()
{
return header;
}
private char[] clOrdID = new char[1];
/* ClOrdID = 11 */
public char[] clOrdID()
{
if (buffer != null && clOrdIDLength > 0)
{
clOrdID = buffer.getChars(clOrdID, clOrdIDOffset, clOrdIDLength);
}
return clOrdID;
}
private int clOrdIDOffset;
private int clOrdIDLength;
/* ClOrdID = 11 */
public int clOrdIDLength()
{
return clOrdIDLength;
}
/* ClOrdID = 11 */
public String clOrdIDAsString()
{
return buffer != null ? buffer.getStringWithoutLengthAscii(clOrdIDOffset, clOrdIDLength) : "";
}
/* ClOrdID = 11 */
public AsciiSequenceView clOrdID(final AsciiSequenceView view)
{
return view.wrap(buffer, clOrdIDOffset, clOrdIDLength);
}
private final CharArrayWrapper clOrdIDWrapper = new CharArrayWrapper();
private char[] symbol = new char[1];
/* Symbol = 55 */
public char[] symbol()
{
if (buffer != null && symbolLength > 0)
{
symbol = buffer.getChars(symbol, symbolOffset, symbolLength);
}
return symbol;
}
private int symbolOffset;
private int symbolLength;
/* Symbol = 55 */
public int symbolLength()
{
return symbolLength;
}
/* Symbol = 55 */
public String symbolAsString()
{
return buffer != null ? buffer.getStringWithoutLengthAscii(symbolOffset, symbolLength) : "";
}
/* Symbol = 55 */
public AsciiSequenceView symbol(final AsciiSequenceView view)
{
return view.wrap(buffer, symbolOffset, symbolLength);
}
private final CharArrayWrapper symbolWrapper = new CharArrayWrapper();
private char side = MISSING_CHAR;
/* Side = 54 */
public char side()
{
return side;
}
private final CharArrayWrapper sideWrapper = new CharArrayWrapper();
/* Side = 54 */
public Side sideAsEnum()
{
return Side.decode(side);
}
private byte[] transactTime = new byte[24];
/* TransactTime = 60 */
public byte[] transactTime()
{
if (buffer != null && transactTimeLength > 0)
{
transactTime = buffer.getBytes(transactTime, transactTimeOffset, transactTimeLength);
}
return transactTime;
}
private int transactTimeOffset;
private int transactTimeLength;
/* TransactTime = 60 */
public int transactTimeLength()
{
return transactTimeLength;
}
/* TransactTime = 60 */
public String transactTimeAsString()
{
return buffer != null ? buffer.getStringWithoutLengthAscii(transactTimeOffset, transactTimeLength) : "";
}
/* TransactTime = 60 */
public AsciiSequenceView transactTime(final AsciiSequenceView view)
{
return view.wrap(buffer, transactTimeOffset, transactTimeLength);
}
private DecimalFloat orderQty = DecimalFloat.newNaNValue();
private boolean hasOrderQty;
/* OrderQty = 38 */
public DecimalFloat orderQty()
{
if (!hasOrderQty)
{
throw new IllegalArgumentException("No value for optional field: OrderQty");
}
if (buffer != null && orderQtyLength > 0)
{
orderQty = getFloatFlyweight(buffer, orderQty, orderQtyOffset, orderQtyLength, 38, CODEC_VALIDATION_ENABLED);
}
return orderQty;
}
public boolean hasOrderQty()
{
return hasOrderQty;
}
private int orderQtyOffset;
private int orderQtyLength;
/* OrderQty = 38 */
public int orderQtyLength()
{
if (!hasOrderQty)
{
throw new IllegalArgumentException("No value for optional field: OrderQty");
}
return orderQtyLength;
}
private char ordType = MISSING_CHAR;
/* OrdType = 40 */
public char ordType()
{
return ordType;
}
private final CharArrayWrapper ordTypeWrapper = new CharArrayWrapper();
/* OrdType = 40 */
public OrdType ordTypeAsEnum()
{
return OrdType.decode(ordType);
}
private DecimalFloat price = DecimalFloat.newNaNValue();
/* Price = 44 */
public DecimalFloat price()
{
if (buffer != null && priceLength > 0)
{
price = getFloatFlyweight(buffer, price, priceOffset, priceLength, 44, CODEC_VALIDATION_ENABLED);
}
return price;
}
private int priceOffset;
private int priceLength;
/* Price = 44 */
public int priceLength()
{
return priceLength;
}
public int decode(final AsciiBuffer buffer, final int offset, final int length)
{
// Decode NewOrderSingle
int seenFieldCount = 0;
if (CODEC_VALIDATION_ENABLED)
{
missingRequiredFields.copy(REQUIRED_FIELDS);
alreadyVisitedFields.clear();
}
this.buffer = buffer;
final int end = offset + length;
int position = offset;
position += header.decode(buffer, position, length);
int tag;
while (position < end)
{
final int equalsPosition = buffer.scan(position, end, '=');
if (equalsPosition == AsciiBuffer.UNKNOWN_INDEX)
{
return position;
}
tag = buffer.getInt(position, equalsPosition);
final int valueOffset = equalsPosition + 1;
int endOfField = buffer.scan(valueOffset, end, START_OF_HEADER);
if (endOfField == AsciiBuffer.UNKNOWN_INDEX)
{
rejectReason = 5;
break;
}
final int valueLength = endOfField - valueOffset;
if (CODEC_VALIDATION_ENABLED)
{
if (tag <= 0)
{
invalidTagId = tag;
rejectReason = 0;
}
else if (valueLength == 0)
{
invalidTagId = tag;
rejectReason = 4;
}
if (!alreadyVisitedFields.add(tag))
{
invalidTagId = tag;
rejectReason = 13;
}
missingRequiredFields.remove(tag);
seenFieldCount++;
}
switch (tag)
{
case Constants.CL_ORD_ID:
clOrdIDOffset = valueOffset;
clOrdIDLength = valueLength;
break;
case Constants.SYMBOL:
symbolOffset = valueOffset;
symbolLength = valueLength;
break;
case Constants.SIDE:
side = buffer.getChar(valueOffset);
break;
case Constants.TRANSACT_TIME:
transactTimeOffset = valueOffset;
transactTimeLength = valueLength;
break;
case Constants.ORDER_QTY:
hasOrderQty = true;
orderQtyOffset = valueOffset;
orderQtyLength = valueLength;
break;
case Constants.ORD_TYPE:
ordType = buffer.getChar(valueOffset);
break;
case Constants.PRICE:
priceOffset = valueOffset;
priceLength = valueLength;
break;
default:
if (!CODEC_REJECT_UNKNOWN_FIELD_ENABLED)
{
alreadyVisitedFields.remove(tag);
}
else
{
if (!(trailer.REQUIRED_FIELDS.contains(tag)))
{
unknownFields.add(tag);
}
}
if (CODEC_REJECT_UNKNOWN_FIELD_ENABLED || (trailer.REQUIRED_FIELDS.contains(tag)))
{
position += trailer.decode(buffer, position, end - position);
return position - offset;
}
}
if (position < (endOfField + 1))
{
position = endOfField + 1;
}
}
position += trailer.decode(buffer, position, end - position);
return position - offset;
}
public void reset()
{
header.reset();
trailer.reset();
resetMessage();
buffer = null;
if (CODEC_VALIDATION_ENABLED)
{
invalidTagId = Decoder.NO_ERROR;
rejectReason = Decoder.NO_ERROR;
missingRequiredFields.clear();
unknownFields.clear();
alreadyVisitedFields.clear();
}
}
public void resetMessage()
{
this.resetClOrdID();
this.resetSide();
this.resetTransactTime();
this.resetOrdType();
this.resetPrice();
this.resetSymbol();
this.resetOrderQty();
}
public void resetClOrdID()
{
clOrdIDOffset = 0;
clOrdIDLength = 0;
}
public void resetSide()
{
side = MISSING_CHAR;
}
public void resetTransactTime()
{
}
public void resetOrdType()
{
ordType = MISSING_CHAR;
}
public void resetPrice()
{
priceLength = 0;
price.reset();
}
public void resetSymbol()
{
symbolOffset = 0;
symbolLength = 0;
}
public void resetOrderQty()
{
hasOrderQty = false;
}
public String toString()
{
return appendTo(new StringBuilder()).toString();
}
public StringBuilder appendTo(final StringBuilder builder)
{
return appendTo(builder, 1);
}
public StringBuilder appendTo(final StringBuilder builder, final int level)
{
builder.append("{\n"); indent(builder, level);
builder.append("\"MessageName\": \"NewOrderSingle\",\n");
builder.append(" \"header\": ");
header.appendTo(builder, level + 1);
builder.append("\n");
indent(builder, level);
builder.append("\"ClOrdID\": \"");
builder.append(this.clOrdID(), 0, clOrdIDLength());
builder.append("\",\n");
indent(builder, level);
builder.append("\"Symbol\": \"");
builder.append(this.symbol(), 0, symbolLength());
builder.append("\",\n");
indent(builder, level);
builder.append("\"Side\": \"");
builder.append(this.side());
builder.append("\",\n");
indent(builder, level);
builder.append("\"TransactTime\": \"");
appendData(builder, this.transactTime(), transactTimeLength());
builder.append("\",\n");
if (hasOrderQty())
{
indent(builder, level);
builder.append("\"OrderQty\": \"");
this.orderQty().appendTo(builder);
builder.append("\",\n");
}
indent(builder, level);
builder.append("\"OrdType\": \"");
builder.append(this.ordType());
builder.append("\",\n");
indent(builder, level);
builder.append("\"Price\": \"");
this.price().appendTo(builder);
builder.append("\",\n");
indent(builder, level - 1);
builder.append("}");
return builder;
}
public NewOrderSingleEncoder toEncoder(final Encoder encoder)
{
return toEncoder((NewOrderSingleEncoder)encoder);
}
public NewOrderSingleEncoder toEncoder(final NewOrderSingleEncoder encoder)
{
encoder.reset();
encoder.clOrdID(this.clOrdID(), 0, clOrdIDLength());
final InstrumentEncoder instrument = encoder.instrument(); instrument.symbol(this.symbol(), 0, symbolLength());
encoder.side(this.side());
encoder.transactTimeAsCopy(this.transactTime(), 0, transactTimeLength());
final OrderQtyDataEncoder orderQtyData = encoder.orderQtyData(); if (hasOrderQty())
{
orderQtyData.orderQty(this.orderQty());
}
encoder.ordType(this.ordType());
encoder.price(this.price()); return encoder;
}
}