buffer = new MutableAsciiBuffer(byteBuffer);
public String getLatestMessage() { return latestTestRequestMessageBuffer.getAscii(0, latestTestRequestMessageLength); }
public int putAscii(final int index, final String string) { final byte[] bytes = string.getBytes(US_ASCII); putBytes(index, bytes); return bytes.length; }
private boolean validateChecksum( final int endOfMessage, final int startOfChecksumValue, final int offset, final int startOfChecksumTag) { final int expectedChecksum = buffer.getInt(startOfChecksumValue - 1, endOfMessage); final int computedChecksum = buffer.computeChecksum(offset, startOfChecksumTag + 1); return expectedChecksum == computedChecksum; }
final int messageEndOffset) mutableAsciiFlyweight.wrap(claimBuffer); final int lengthOfNewBodyLength = MutableAsciiBuffer.lengthInAscii(newBodyLength); mutableAsciiFlyweight.putBytes( index, mutableAsciiFlyweight, mutableAsciiFlyweight.putNaturalPaddedIntAscii( bodyLengthClaimOffset, lengthOfUpdatedBodyLengthField, newBodyLength);
int pollData() throws IOException { final ByteBuffer buffer = ByteBuffer.allocateDirect(BUFFER_SIZE); final MutableAsciiBuffer asciiBuffer = new MutableAsciiBuffer(buffer); socket.configureBlocking(false); final int read = socket.read(buffer); socket.configureBlocking(true); if (read > 0) { DebugLogger.log(FIX_TEST, "< [" + asciiBuffer.getAscii(OFFSET, read) + "] for poll"); } return read; }
@Test public void canEncodeDecimalFloat() { final int length = input.length(); final UnsafeBuffer buffer = new UnsafeBuffer(new byte[LONGEST_FLOAT_LENGTH]); final MutableAsciiBuffer string = new MutableAsciiBuffer(buffer); final DecimalFloat price = new DecimalFloat(value, scale); final int encodedLength = string.putFloatAscii(1, price); assertEquals(input, string.getAscii(1, length)); assertEquals(length, encodedLength); } }
private void canDecodeDecimalFloatFromBytes(final byte[] bytes) { final MutableAsciiBuffer string = new MutableAsciiBuffer(new byte[bytes.length + 2]); string.putBytes(1, bytes); final DecimalFloat price = new DecimalFloat(); string.getFloat(price, 1, bytes.length); Assert.assertEquals("Incorrect Value", value, price.value()); Assert.assertEquals("Incorrect Scale", scale, price.scale()); }
private void canParseTimestamp(final int length) { final long expectedEpochMillis = toEpochMillis(timestamp); final byte[] bytes = timestamp.getBytes(US_ASCII); final MutableAsciiBuffer buffer = new MutableAsciiBuffer(new byte[LENGTH_WITH_MICROSECONDS + 2]); buffer.putBytes(1, bytes); final long epochMillis = UtcTimestampDecoder.decode(buffer, 1, length); assertEquals("Failed Millis testcase for: " + timestamp, expectedEpochMillis, epochMillis); long expectedEpochMicros = expectedEpochMillis * MICROS_IN_MILLIS; // If they've got the suffix field, then test microseconds, add 1 to the value if (timestamp.length() == LENGTH_WITH_MILLISECONDS) { expectedEpochMicros++; buffer.putAscii(timestamp.length() + 1, "001"); } final long epochMicros = UtcTimestampDecoder.decodeMicros(buffer, 1, length + 3); assertEquals("Failed Micros testcase for: " + timestamp, expectedEpochMicros, epochMicros); }
if (zero(offset, value)) final long remainder = calculateRemainderAndPutMinus(offset, value); final int minusAdj = value < 0 ? 1 : 0; final int start = offset + minusAdj; final int tmpStart = putLong(remainder, tmpEnd) + 1; final int length = tmpEnd - tmpStart + 1; putByte(cursor++, ZERO); putByte(cursor++, DOT); final int numberOfZeros = -digitsBeforeDot; final int endOfZeros = cursor + numberOfZeros; for (; cursor < endOfZeros; cursor++) putByte(cursor, ZERO); putBytes(cursor, this, tmpStart, length); putBytes(start, this, tmpStart, digitsBeforeDot); putByte(split, DOT); putBytes(split + 1, this, tmpStart + digitsBeforeDot, scale); putBytes(start, this, tmpStart, length); return length + minusAdj;
public Action onMessage( final DirectBuffer buffer, final int offset, final int length, final int libraryId, final Session session, final int sequenceIndex, final int messageType, final long timestampInNs, final long position) { if (messageType == ExecutionReportDecoder.MESSAGE_TYPE) { asciiBuffer.wrap(buffer, offset, length); System.out.println("Received report: " + asciiBuffer.getAscii(0, length)); executionReport.decode(asciiBuffer, 0, length); System.out.println("Parsed report: " + executionReport); state = State.SESSION_CONNECTED; } return CONTINUE; }
public UtcTimestampEncoder(final boolean usesMilliseconds) { this.usesMilliseconds = usesMilliseconds; flyweight.wrap(bytes); }
for (int index = end - 1; isSpace(index) && index > offset; index--) for (int index = end - 1; isZero(index) && index > offset; index--) for (int index = end - endDiff - 1; index > offset; index--) if (getByte(index) == DOT) for (int index = offset; isSpace(index) && index < end; index++) final boolean negative = getByte(offset) == '-'; if (negative) for (int index = offset; isZero(index) && index < end; index++) for (int index = offset; index < end; index++) final byte byteValue = getByte(index); if (byteValue == DOT) final int digit = getDigit(index, byteValue); value = value * 10 + digit;
private int getMessageType(final int endOfBodyLength, final int indexOfLastByteOfMessage) { final int start = buffer.scan(endOfBodyLength, indexOfLastByteOfMessage, '='); if (buffer.getByte(start + 2) == START_OF_HEADER) { return buffer.getByte(start + 1); } return buffer.getMessageType(start + 1, 2); }
private void setPossDupFlag( final int possDupSrcOffset, final int messageOffset, final int claimOffset, final MutableDirectBuffer claimBuffer) { final int possDupClaimOffset = srcToClaim(possDupSrcOffset, messageOffset, claimOffset); mutableAsciiFlyweight.wrap(claimBuffer); mutableAsciiFlyweight.putChar(possDupClaimOffset, 'Y'); }
private void assertDecodesMonthYear(final String input, final MonthYear expectedMonthYear) { final UnsafeBuffer buffer = new UnsafeBuffer(new byte[input.length()]); final MutableAsciiBuffer asciiFlyweight = new MutableAsciiBuffer(buffer); asciiFlyweight.putAscii(0, input); final boolean decode = monthYear.decode(asciiFlyweight, 0, input.length()); assertTrue(String.format("Failed to decode %s correctly", input), decode); assertEquals(expectedMonthYear, monthYear); }