void appendInstance(final Bytes bytes, final V value) {
   bytes.clear();
   if (generatedValueType) ((BytesMarshallable) value).writeMarshallable(bytes);
   else bytes.writeInstance(vClass, value);
   bytes.flip();
   appendValue(bytes);
 }
Ejemplo n.º 2
0
  public static void main(String... ignored) {
    ByteBuffer wrap = ByteBuffer.allocate(1024);
    Bytes bufferBytes = ByteBufferBytes.wrap(wrap);
    byte[] bytes = "BAC,12.32,12.54,12.56,232443".getBytes();

    int runs = 10000000;
    long start = System.nanoTime();
    for (int i = 0; i < runs; i++) {
      bufferBytes.clear();
      // read the next message.
      bufferBytes.write(bytes);
      bufferBytes.position(0);
      // decode message
      String word = bufferBytes.parseUtf8(StopCharTesters.COMMA_STOP);
      double low = bufferBytes.parseDouble();
      double curr = bufferBytes.parseDouble();
      double high = bufferBytes.parseDouble();
      long sequence = bufferBytes.parseLong();
      if (i == 0) {
        assertEquals("BAC", word);
        assertEquals(12.32, low, 0.0);
        assertEquals(12.54, curr, 0.0);
        assertEquals(12.56, high, 0.0);
        assertEquals(232443, sequence);
      }
    }
    long time = System.nanoTime() - start;
    System.out.println("Average time was " + time / runs + " nano-seconds");
  }