Java Code Examples for net.openhft.chronicle.bytes.Bytes#from()

The following examples show how to use net.openhft.chronicle.bytes.Bytes#from() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FixSaxParserTest.java    From SAXophone with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testParseSingleOrder() {
    String s = "8=FIX.4.2|9=130|35=D|34=659|49=BROKER04|56=REUTERS|52=20070123-19:09:43|38=1000|59=1|100=N|40=1|11=ORD10001|60=20070123-19:01:17|55=HPQ|54=1|21=2|10=004|";
    Bytes bbb = Bytes.from(s.replace('|', '\u0001'));
    final StringBuilder sb = new StringBuilder();
    FixSaxParser parser = new FixSaxParser(new FixHandler() {
        @Override
        public void onField(long fieldNumber, Bytes value) {
            sb.append(fieldNumber).append("=")
                    .append(value.toString()).append("|");
        }

        @Override
        public void completeMessage(Bytes bytes) {

        }
    });parser.parse(bbb);
    assertEquals(s, sb.toString());
}
 
Example 2
Source File: FixSaxParserTest.java    From SAXophone with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void timeParseSingleOrder() {
    String s = "8=FIX.4.2|9=130|35=D|34=659|49=BROKER04|56=REUTERS|52=20070123-19:09:43|38=1000|59=1|100=N|40=1|11=ORD10001|60=20070123-19:01:17|55=HPQ|54=1|21=2|10=004|";
    Bytes nb = Bytes.from(s.replace('|', '\u0001'));

    final AtomicInteger count = new AtomicInteger();
    FixSaxParser parser = new FixSaxParser(new MyFixHandler(count));
    int runs = 200000;
    for (int t = 0; t < 5; t++) {
        count.set(0);
        long start = System.nanoTime();
        for (int i = 0; i < runs; i++) {
            nb.readPosition(0);
            parser.parse(nb);
        }
        long time = System.nanoTime() - start;
        System.out.printf("Average parse time was %.2f us, fields per message %.2f%n",
                time / runs / 1e3, (double) count.get() / runs);
    }
}
 
Example 3
Source File: JsonParser.java    From SAXophone with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Bytes finishSpace() {
    if (finishSpace == null) {
        finishSpace = Bytes.from(" ");
    }
    finishSpace.readPosition(0);
    return finishSpace;
}
 
Example 4
Source File: JsonParserTest.java    From SAXophone with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Bytes stringToBytes(String json) {
        return Bytes.from(json);
}