use of com.ociweb.pronghorn.pipe.DataInputBlobReader in project PronghornPipes by oci-pronghorn.
the class MessageConsumer method storeValue.
private void storeValue(ChannelReader reader, int type, FieldConsumer consumer) {
// NB: the order of these are from most common to least common
if (type < 0x0B) {
if (type < 0x0A) {
// integers
consumer.store(reader.readPackedLong());
} else {
Pipe backingPipe = DataInputBlobReader.getBackingPipe((DataInputBlobReader) reader);
short length = reader.readShort();
consumer.store(backingPipe.blobRing, DataInputBlobReader.absolutePosition((DataInputBlobReader) reader), length, backingPipe.blobMask);
if (length > 0) {
reader.skipBytes(length);
}
}
} else {
// >=0x0B
if (type == TypeMask.ByteVector) {
// bytes
Pipe backingPipe = DataInputBlobReader.getBackingPipe((DataInputBlobReader) reader);
short length = reader.readShort();
consumer.store(backingPipe.blobRing, DataInputBlobReader.absolutePosition((DataInputBlobReader) reader), length, backingPipe.blobMask);
if (length > 0) {
reader.skipBytes(length);
}
} else {
if (type == TypeMask.Decimal) {
// decimal
consumer.store(reader.readByte(), reader.readPackedLong());
} else {
// rational
consumer.store(reader.readPackedLong(), reader.readPackedLong());
}
}
}
}
use of com.ociweb.pronghorn.pipe.DataInputBlobReader in project PronghornPipes by oci-pronghorn.
the class TrieParserTest method testwriteCapturedUTF8ToPipe.
@Test
public void testwriteCapturedUTF8ToPipe() throws IOException {
TrieParserReader reader = new TrieParserReader(3);
TrieParser map = new TrieParser(16);
// map.setValue(wrapping(dataBytesExtractStart,4), 0,
// dataBytesExtractStart.length, 15, value2);
map.setUTF8Value("%b1234", 33);
CharSequence test1 = "abcd1234";
reader.query(map, test1);
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);
// just like in test above, will return the number of captured bytes 4
// in this case(abcd).
int num = TrieParserReader.writeCapturedUTF8ToPipe(reader, pipe, 0, RawDataSchema.MSG_CHUNKEDSTREAM_1_FIELD_BYTEARRAY_2);
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);
Pipe.confirmLowLevelRead(pipe, size);
Pipe.releaseReadLock(pipe);
assertEquals(num, 4);
}
use of com.ociweb.pronghorn.pipe.DataInputBlobReader in project PronghornPipes by oci-pronghorn.
the class TrieParserTest method testwriteCapturedUTF8.
@Test
public void testwriteCapturedUTF8() {
TrieParserReader reader = new TrieParserReader(3);
TrieParser map = new TrieParser(16);
map.setUTF8Value("12%b1234", 33);
CharSequence test = "12abcd1234";
// 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);
// will append "abcd" to blobWriter
int val = TrieParserReader.writeCapturedUTF8(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();
StringBuilder str = new StringBuilder();
y.readUTFOfLength(y.available(), str);
// value of blobwriter sent to stringbuilder to sompare with other
// string
assertEquals(str.toString().trim(), "abcd");
}
use of com.ociweb.pronghorn.pipe.DataInputBlobReader in project PronghornPipes by oci-pronghorn.
the class TrieParserTest method testparseGather.
@Test
public void testparseGather() {
TrieParserReader reader = new TrieParserReader(3);
TrieParser map = new TrieParser(16);
map.setUTF8Value("12%b12", 33);
CharSequence test = "12abcd12";
TrieParserReader.parseSetup(reader, "12abcd12".getBytes(), 0, 8, 7);
long val = 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);
// so will give 5. 5 bytes
reader.parseGather(reader, x, (byte) 'd');
// until d is hit. if i put
// 'c' will return length of
// 4.
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);
// dont understand what this parseGather() is supposed to do.
reader.parseGather(reader, (byte) 'd');
// just changes sourcePos? but this shouldne be 22 if my sixe of source
// array is only like 8
assertEquals(str.length(), 5);
assertEquals(str.toString(), "12abc");
assertEquals(22, reader.sourcePos);
}
use of com.ociweb.pronghorn.pipe.DataInputBlobReader in project PronghornPipes by oci-pronghorn.
the class TrieParserTest method testwriteCapturedValuesToDataOutput.
@Test
public void testwriteCapturedValuesToDataOutput() throws IOException {
TrieParserReader reader = new TrieParserReader(3);
TrieParser map = new TrieParser(16);
// map.setValue(wrapping(dataBytesExtractStart,4), 0,
// dataBytesExtractStart.length, 15, value2);
map.setUTF8Value("%b1234", 33);
CharSequence test1 = "abcd1234";
reader.query(map, test1);
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);
// write something
// ->
int numCapturedBytes = TrieParserReader.writeCapturedValuesToDataOutput(reader, x);
// should
// equal
// 4
// from
// above
// ex.
x.closeLowLevelField();
Pipe.confirmLowLevelWrite(pipe, size);
Pipe.publishWrites(pipe);
// /////////
int msg = Pipe.takeMsgIdx(pipe);
assertEquals(RawDataSchema.MSG_CHUNKEDSTREAM_1, msg);
// String value = Pipe.takeUTF8(pipe); //something with UTF in method
// name
DataInputBlobReader y = Pipe.inputStream(pipe);
y.openLowLevelAPIField();
StringBuilder str = new StringBuilder();
y.readUTFOfLength(y.available(), str);
// assert("safdsfasdf", value);
Pipe.confirmLowLevelRead(pipe, size);
Pipe.releaseReadLock(pipe);
assertEquals(numCapturedBytes, 4);
// test to cover unsigned decimal value.
reader = new TrieParserReader(3);
map = new TrieParser(16);
map.setUTF8Value("%i%.", 33);
String test2 = "3.75";
reader.query(map, test2);
pipe = RawDataSchema.instance.newPipe(2, 64);
pipe.initBuffers();
size = Pipe.addMsgIdx(pipe, RawDataSchema.MSG_CHUNKEDSTREAM_1);
x = Pipe.outputStream(pipe);
DataOutputBlobWriter.openField(x);
// write something
// ->
numCapturedBytes = TrieParserReader.writeCapturedValuesToDataOutput(reader, x);
// should
// equal
// 4
// from
// above
// ex.
x.closeLowLevelField();
Pipe.confirmLowLevelWrite(pipe, size);
Pipe.publishWrites(pipe);
// /////////
msg = Pipe.takeMsgIdx(pipe);
assertEquals(RawDataSchema.MSG_CHUNKEDSTREAM_1, msg);
y = Pipe.inputStream(pipe);
y.openLowLevelAPIField();
// this will return 375 for "3.75
long l1 = y.readPackedLong();
// this will give us a -2, to tell us where the
int b1 = y.read();
// decimal should go.
Pipe.confirmLowLevelRead(pipe, size);
Pipe.releaseReadLock(pipe);
assertEquals(l1, 375);
assertEquals(b1, -2);
}
Aggregations