blob: 25b1a6acff4593e4b41d5499c035c0a40f061ac7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vdslib;
import com.yahoo.document.DocumentTypeManager;
import com.yahoo.vespa.objects.Serializer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
* @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
*/
class BinaryDocumentList extends DocumentList {
private DocumentTypeManager docMan;
private byte[] buffer;
private int docCount;
/**
* Create a new documentlist, using the given buffer.
*
* @param buffer buffer containing documents
*/
BinaryDocumentList(DocumentTypeManager docMan, byte[] buffer) {
this.docMan = docMan;
ByteBuffer buf = ByteBuffer.wrap(buffer);
buf.order(ByteOrder.LITTLE_ENDIAN);
docCount = buf.getInt();
this.buffer = buffer;
}
@Override
public Entry get(int index) throws ArrayIndexOutOfBoundsException {
if (index < docCount) {
return Entry.create(docMan, buffer, index);
} else {
throw new ArrayIndexOutOfBoundsException(index + " >= " + docCount);
}
}
@Override
public int size() { return docCount; }
@Override
public int getApproxByteSize() {
return buffer.length;
}
@Override
public void serialize(Serializer buf) {
buf.put(null, buffer);
}
}
|