uk.co.real_logic.artio.decoder_flyweight.ResendRequestDecoder 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.decoder_flyweight;
import uk.co.real_logic.artio.decoder.AbstractResendRequestDecoder;
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.decoder_flyweight.HeaderDecoder;
import uk.co.real_logic.artio.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.*;
import uk.co.real_logic.artio.builder.ResendRequestEncoder;
@Generated("uk.co.real_logic.artio")
public class ResendRequestDecoder extends CommonDecoderImpl implements MessageDecoder, AbstractResendRequestDecoder
{
public final IntHashSet REQUIRED_FIELDS = new IntHashSet(4);
{
if (CODEC_VALIDATION_ENABLED)
{
REQUIRED_FIELDS.add(Constants.BEGIN_SEQ_NO);
REQUIRED_FIELDS.add(Constants.END_SEQ_NO);
}
}
private final IntHashSet alreadyVisitedFields = new IntHashSet(4);
private final IntHashSet unknownFields = new IntHashSet(10);
private final IntHashSet missingRequiredFields = new IntHashSet(4);
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;
}
return true;
}
public static final long MESSAGE_TYPE = 50L;
public static final String MESSAGE_TYPE_AS_STRING = "2";
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(36);
{
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.BEGIN_SEQ_NO);
messageFields.add(Constants.END_SEQ_NO);
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 int beginSeqNo = MISSING_INT;
/* BeginSeqNo = 7 */
public int beginSeqNo()
{
if (buffer != null && beginSeqNoLength > 0)
{
beginSeqNo = getIntFlyweight(buffer, beginSeqNoOffset, beginSeqNoLength, 7, CODEC_VALIDATION_ENABLED);
}
return beginSeqNo;
}
private int beginSeqNoOffset;
private int beginSeqNoLength;
/* BeginSeqNo = 7 */
public int beginSeqNoLength()
{
return beginSeqNoLength;
}
private int endSeqNo = MISSING_INT;
/* EndSeqNo = 16 */
public int endSeqNo()
{
if (buffer != null && endSeqNoLength > 0)
{
endSeqNo = getIntFlyweight(buffer, endSeqNoOffset, endSeqNoLength, 16, CODEC_VALIDATION_ENABLED);
}
return endSeqNo;
}
private int endSeqNoOffset;
private int endSeqNoLength;
/* EndSeqNo = 16 */
public int endSeqNoLength()
{
return endSeqNoLength;
}
public int decode(final AsciiBuffer buffer, final int offset, final int length)
{
// Decode ResendRequest
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.BEGIN_SEQ_NO:
beginSeqNoOffset = valueOffset;
beginSeqNoLength = valueLength;
break;
case Constants.END_SEQ_NO:
endSeqNoOffset = valueOffset;
endSeqNoLength = 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.resetBeginSeqNo();
this.resetEndSeqNo();
}
public void resetBeginSeqNo()
{
beginSeqNoLength = 0;
beginSeqNo = MISSING_INT;
}
public void resetEndSeqNo()
{
endSeqNoLength = 0;
endSeqNo = MISSING_INT;
}
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\": \"ResendRequest\",\n");
builder.append(" \"header\": ");
header.appendTo(builder, level + 1);
builder.append("\n");
indent(builder, level);
builder.append("\"BeginSeqNo\": \"");
builder.append(this.beginSeqNo());
builder.append("\",\n");
indent(builder, level);
builder.append("\"EndSeqNo\": \"");
builder.append(this.endSeqNo());
builder.append("\",\n");
indent(builder, level - 1);
builder.append("}");
return builder;
}
public ResendRequestEncoder toEncoder(final Encoder encoder)
{
return toEncoder((ResendRequestEncoder)encoder);
}
public ResendRequestEncoder toEncoder(final ResendRequestEncoder encoder)
{
encoder.reset();
encoder.beginSeqNo(this.beginSeqNo());
encoder.endSeqNo(this.endSeqNo()); return encoder;
}
}