use of com.yahoo.vespa.objects.BufferSerializer in project vespa by vespa-engine.
the class VespaBackEndSearcher method addMetaInfo.
protected void addMetaInfo(Query query, QueryPacketData queryPacketData, QueryResultPacket resultPacket, Result result, boolean fromCache) {
result.setTotalHitCount(resultPacket.getTotalDocumentCount());
// Grouping
if (resultPacket.getGroupData() != null) {
byte[] data = resultPacket.getGroupData();
ArrayList<Grouping> list = new ArrayList<>();
BufferSerializer buf = new BufferSerializer(new GrowableByteBuffer(ByteBuffer.wrap(data)));
int cnt = buf.getInt(null);
for (int i = 0; i < cnt; i++) {
Grouping g = new Grouping();
g.deserialize(buf);
list.add(g);
}
GroupingListHit hit = new GroupingListHit(list, getDocsumDefinitionSet(query));
hit.setQuery(result.getQuery());
hit.setSource(getName());
hit.setSourceNumber(sourceNumber);
hit.setQueryPacketData(queryPacketData);
result.hits().add(hit);
}
if (resultPacket.getCoverageFeature()) {
result.setCoverage(new Coverage(resultPacket.getCoverageDocs(), resultPacket.getActiveDocs(), resultPacket.getNodesReplied()).setSoonActive(resultPacket.getSoonActiveDocs()).setDegradedReason(resultPacket.getDegradedReason()).setNodesTried(resultPacket.getNodesQueried()));
}
}
use of com.yahoo.vespa.objects.BufferSerializer in project vespa by vespa-engine.
the class ExpressionCountAggregationResultTest method testSerialization.
private void testSerialization(ExpressionCountAggregationResult from, ExpressionCountAggregationResult to) {
BufferSerializer buffer = new BufferSerializer();
from.serialize(buffer);
buffer.flip();
to.deserialize(buffer);
assertEquals(from.getSketch(), to.getSketch());
}
use of com.yahoo.vespa.objects.BufferSerializer in project vespa by vespa-engine.
the class NormalSketchTest method testSerializationForPrecision.
private static void testSerializationForPrecision(int precision) {
// precision p => 2^p bytes
NormalSketch from = new NormalSketch(precision);
for (int i = 0; i < from.size(); i++) {
from.data()[i] = (byte) i;
}
NormalSketch to = new NormalSketch(precision);
BufferSerializer buffer = new BufferSerializer();
from.serialize(buffer);
buffer.flip();
to.deserialize(buffer);
assertEquals(from, to);
}
use of com.yahoo.vespa.objects.BufferSerializer in project vespa by vespa-engine.
the class StringTestCase method testSerializeDeserialize.
/* public void testSpanTree() {
StringFieldValue annotatedText = new StringFieldValue("banana airlines");
SpanList lingTree = new SpanList();
annotatedText.setSpanTree("linguistics", lingTree);
for (Annotation anAnnotation : annotatedText.getSpanTree("linguistics")) {
System.err.println(anAnnotation);
}
}*/
@Test
public void testSerializeDeserialize() throws Exception {
java.lang.String test = "Hello hello";
BufferSerializer data = new BufferSerializer(new GrowableByteBuffer(100, 2.0f));
StringFieldValue value = new StringFieldValue(test);
value.serialize(data);
data.getBuf().position(0);
StringFieldValue tmp = new StringFieldValue();
DocumentDeserializer deser = DocumentDeserializerFactory.create42(null, data.getBuf());
tmp.deserialize(deser);
java.lang.String test2 = tmp.getString();
assertEquals(test, test2);
}
use of com.yahoo.vespa.objects.BufferSerializer in project vespa by vespa-engine.
the class DocumentIdTestCase method testSerializedDocumentIdCanContainNonTextCharacter.
@Test
public void testSerializedDocumentIdCanContainNonTextCharacter() throws UnsupportedEncodingException {
// "id:a:b::0x7c"
String strId = new String(new byte[] { 105, 100, 58, 97, 58, 98, 58, 58, 7, 99 });
DocumentId docId = DocumentId.createFromSerialized(strId);
{
assertEquals(strId, docId.toString());
}
{
BufferSerializer buf = new BufferSerializer();
docId.serialize(buf);
buf.flip();
DocumentId deserializedId = new DocumentId(buf);
assertEquals(strId, deserializedId.toString());
}
}
Aggregations