Skip to content

Commit

Permalink
Merge pull request #473 from jvirtanen/improvements/message-parser
Browse files Browse the repository at this point in the history
philadelphia-core: Improve 'FIXMessageParser'
  • Loading branch information
jvirtanen authored Jul 14, 2024
2 parents 94d1d90 + a2340b6 commit 4c7c1f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ class FIX {

static final byte NO = 'N';

static final byte[] BEGIN_STRING = { '8', '=' };
static final byte[] BEGIN_STRING_BYTES = { '8', '=' };

static final byte[] BODY_LENGTH = { '9', '=' };
static final byte[] BODY_LENGTH_BYTES = { '9', '=' };

static final byte[] CHECK_SUM = { '1', '0', '=' };
static final byte[] CHECK_SUM_BYTES = { '1', '0', '=' };

static final short BEGIN_STRING_SHORT = '8' << 8 | '=';

static final short BODY_LENGTH_SHORT = '9' << 8 | '=';

static final int BODY_LENGTH_FIELD_CAPACITY = 16;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ public FIXConnection(ReadableByteChannel rxChannel, GatheringByteChannel txChann

this.txHeaderBuffer = ByteBuffer.allocateDirect(config.getTxBufferCapacity());

this.txHeaderBuffer.put(BEGIN_STRING);
this.txHeaderBuffer.put(BEGIN_STRING_BYTES);
this.txHeaderBuffer.put(config.getBeginString());
this.txHeaderBuffer.put(SOH);
this.txHeaderBuffer.put(BODY_LENGTH);
this.txHeaderBuffer.put(BODY_LENGTH_BYTES);

this.bodyLengthOffset = this.txHeaderBuffer.position();

Expand Down Expand Up @@ -518,7 +518,7 @@ public void send(FIXMessage message) throws IOException {
checkSum.setCheckSum(FIXCheckSums.sum(txHeaderBuffer, 0, txHeaderBuffer.position()) +
FIXCheckSums.sum(txBodyBuffer, 0, txBodyBuffer.position()));

txBodyBuffer.put(CHECK_SUM);
txBodyBuffer.put(CHECK_SUM_BYTES);
checkSum.put(txBodyBuffer);

txHeaderBuffer.flip();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public boolean parse(ByteBuffer buffer) throws IOException {
return false;

// Garbled message
garbled = buffer.get() != '8' || buffer.get() != '=';
garbled = buffer.getShort() != BEGIN_STRING_SHORT;

// Partial message
if (!skipValue(buffer)) {
Expand All @@ -89,7 +89,7 @@ public boolean parse(ByteBuffer buffer) throws IOException {
}

// Garbled message
garbled = buffer.get() != '9' || buffer.get() != '=';
garbled = buffer.getShort() != BODY_LENGTH_SHORT;

int bodyLength = getInt(buffer);

Expand Down

0 comments on commit 4c7c1f2

Please sign in to comment.