aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/DocumentListEntry.java
blob: 9a67dd6f506e742f650fa90ba688fb8a19dc7cd6 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.documentapi.messagebus.protocol;

import com.yahoo.document.Document;
import com.yahoo.document.serialization.DocumentDeserializer;
import com.yahoo.vespa.objects.Serializer;

public class DocumentListEntry {

    private Document doc;
    private long timestamp;
    private boolean removeEntry;

    public DocumentListEntry(Document doc, long timestamp, boolean removeEntry) {
        this.doc = doc;
        this.timestamp = timestamp;
        this.removeEntry = removeEntry;
    }

    public void serialize(Serializer buf) {
        buf.putLong(null, timestamp);
        doc.serialize(buf);
        buf.putByte(null, (byte)(removeEntry ? 1 : 0));
    }

    public static int getApproxSize() {
        return 60; // optimzation. approximation is sufficient
    }

    public DocumentListEntry(DocumentDeserializer buf) {
        timestamp = buf.getLong(null);
        doc = new Document(buf);
        removeEntry = buf.getByte(null) > 0;
    }

    public Document getDocument() {
        return doc;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public boolean isRemoveEntry() {
        return removeEntry;
    }
}