Search in sources :

Example 6 with DataInputBlobReader

use of com.ociweb.pronghorn.pipe.DataInputBlobReader in project PronghornPipes by oci-pronghorn.

the class TrieParserTest method testparseCopy.

@Test
public void testparseCopy() {
    TrieParserReader reader = new TrieParserReader(3);
    TrieParser map = new TrieParser(16);
    map.setUTF8Value("12%b12", 33);
    CharSequence test = "12abcd12";
    // TrieParserReader that, byte[] source, int offset, int length, int
    // mask
    TrieParserReader.parseSetup(reader, "12%b12".getBytes(), 0, 6, 7);
    assertEquals(6, reader.sourceLen);
    Pipe<RawDataSchema> pipe = RawDataSchema.instance.newPipe(2, 64);
    pipe.initBuffers();
    int size = Pipe.addMsgIdx(pipe, RawDataSchema.MSG_CHUNKEDSTREAM_1);
    DataOutputBlobWriter x = Pipe.outputStream(pipe);
    DataOutputBlobWriter.openField(x);
    // will copy the
    int val = TrieParserReader.parseCopy(reader, 6, x);
    // value in mapping
    // to
    // dataoutputblobwriter
    x.closeLowLevelField();
    Pipe.confirmLowLevelWrite(pipe, size);
    Pipe.publishWrites(pipe);
    // /////////
    int msg = Pipe.takeMsgIdx(pipe);
    assertEquals(RawDataSchema.MSG_CHUNKEDSTREAM_1, msg);
    DataInputBlobReader y = Pipe.inputStream(pipe);
    y.openLowLevelAPIField();
    StringBuilder str = new StringBuilder();
    y.readUTFOfLength(y.available(), str);
    assertEquals(str.toString(), "12%b12");
    // asserting length returned by parseCopy is
    assertEquals(val, 6);
// length given. would not be the case if
// sourcelength was greater.
}
Also used : RawDataSchema(com.ociweb.pronghorn.pipe.RawDataSchema) DataInputBlobReader(com.ociweb.pronghorn.pipe.DataInputBlobReader) DataOutputBlobWriter(com.ociweb.pronghorn.pipe.DataOutputBlobWriter) Test(org.junit.Test)

Example 7 with DataInputBlobReader

use of com.ociweb.pronghorn.pipe.DataInputBlobReader in project PronghornPipes by oci-pronghorn.

the class TrieParserTest method testwriteCapturedShort.

@Test
public void testwriteCapturedShort() {
    TrieParserReader reader = new TrieParserReader(3);
    TrieParser map = new TrieParser(16);
    map.setUTF8Value("12%iabcd", 33);
    CharSequence test = "128abcd";
    // query holds most recent thing
    reader.query(map, test);
    Pipe<RawDataSchema> pipe = RawDataSchema.instance.newPipe(2, 64);
    pipe.initBuffers();
    int size = Pipe.addMsgIdx(pipe, RawDataSchema.MSG_CHUNKEDSTREAM_1);
    DataOutputBlobWriter x = Pipe.outputStream(pipe);
    DataOutputBlobWriter.openField(x);
    TrieParserReader.writeCapturedShort(reader, 0, x);
    x.closeLowLevelField();
    Pipe.confirmLowLevelWrite(pipe, size);
    Pipe.publishWrites(pipe);
    // /////////
    int msg = Pipe.takeMsgIdx(pipe);
    assertEquals(RawDataSchema.MSG_CHUNKEDSTREAM_1, msg);
    DataInputBlobReader y = Pipe.inputStream(pipe);
    y.openLowLevelAPIField();
    // 2nd value has length of captured field.
    byte[] vals = new byte[2];
    y.read(vals);
    assertEquals(vals[1], 8);
}
Also used : RawDataSchema(com.ociweb.pronghorn.pipe.RawDataSchema) DataInputBlobReader(com.ociweb.pronghorn.pipe.DataInputBlobReader) DataOutputBlobWriter(com.ociweb.pronghorn.pipe.DataOutputBlobWriter) Test(org.junit.Test)

Aggregations

DataInputBlobReader (com.ociweb.pronghorn.pipe.DataInputBlobReader)7 DataOutputBlobWriter (com.ociweb.pronghorn.pipe.DataOutputBlobWriter)6 RawDataSchema (com.ociweb.pronghorn.pipe.RawDataSchema)6 Test (org.junit.Test)6 Pipe (com.ociweb.pronghorn.pipe.Pipe)1