private void messageIsAHeartBeat() { buffer.putAscii(0, "0"); }
private void onMessage(final Object inst) throws Exception { buffer.putAscii(1, ENCODED_MESSAGE); decoder.getMethod(ON_MESSAGE, AsciiBuffer.class, int.class, int.class, int.class) .invoke(inst, buffer, 1, ENCODED_MESSAGE.length(), '0'); }
private void decode(final String example, final Decoder decoder) { buffer.putAscii(1, example); decoder.decode(buffer, 1, example.length()); }
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); }
@Test public void shouldPrettyPrintAMessage() throws Exception { final Printer printer = printer(); buffer.putAscii(1, ENCODED_MESSAGE); final String string = printer.toString(buffer, 1, ENCODED_MESSAGE.length(), HEARTBEAT_TYPE); assertThat(string, containsString(STRING_ENCODED_MESSAGE_EXAMPLE)); }
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); }