use of com.yahoo.io.GrowableByteBuffer 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.io.GrowableByteBuffer in project vespa by vespa-engine.
the class TensorField method decode.
@Override
public Tensor decode(ByteBuffer buffer) {
int length = buffer.getInt();
if (length == 0)
return null;
ByteBuffer contentBuffer = ByteBuffer.wrap(buffer.array(), buffer.arrayOffset() + buffer.position(), length);
Tensor tensor = TypedBinaryFormat.decode(Optional.empty(), new GrowableByteBuffer(contentBuffer));
buffer.position(buffer.position() + length);
return tensor;
}
use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.
the class Document method serialize.
public void serialize(OutputStream out) throws SerializationException {
DocumentSerializer writer = DocumentSerializerFactory.create42(new GrowableByteBuffer(64 * 1024, 2.0f));
writer.write(this);
GrowableByteBuffer data = writer.getBuf();
byte[] array;
if (data.hasArray()) {
// just get the array
array = data.array();
} else {
// copy the bytebuffer into the array
array = new byte[data.position()];
int endPos = data.position();
data.position(0);
data.get(array);
data.position(endPos);
}
try {
out.write(array, 0, data.position());
} catch (IOException ioe) {
throw new SerializationException(ioe);
}
}
use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.
the class SerializationTestUtils method deserializeDocument.
public static Document deserializeDocument(byte[] buf, TestDocumentFactory factory) {
Document document = factory.createDocument();
DocumentDeserializerFactory.create42(factory.typeManager(), new GrowableByteBuffer(ByteBuffer.wrap(buf))).read(document);
return document;
}
use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.
the class VespaDocumentSerializerTestCase method incompressable_structs_are_serialized_without_buffer_size_overhead_bug.
@Test
public void incompressable_structs_are_serialized_without_buffer_size_overhead_bug() {
CompressionFixture fixture = new CompressionFixture();
Document doc = new Document(fixture.docType, "id:foo:map_of_structs::flarn");
Struct nested = new Struct(fixture.nestedType);
nested.setFieldValue("str", new StringFieldValue(CompressionFixture.COMPRESSABLE_STRING));
MapFieldValue<StringFieldValue, Struct> map = new MapFieldValue<StringFieldValue, Struct>(fixture.mapType);
// Only 1 struct added. Not enough redundant information that header struct containing map itself
// can be compressed.
map.put(new StringFieldValue("foo"), nested);
doc.setFieldValue("map", map);
GrowableByteBuffer buf = CompressionFixture.asSerialized(doc);
// Explanation of arbitrary value: buffer copy bug meant that incompressable structs were all serialized
// rounded up to 4096 bytes.
assertTrue(buf.remaining() < 4096);
}
Aggregations