blob: b2c3cdc09deacfae7ee3c752cd609db69a9aff8a (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.serialization;
import com.yahoo.document.update.TensorAddUpdate;
import com.yahoo.document.update.TensorModifyUpdate;
import com.yahoo.document.update.TensorRemoveUpdate;
import com.yahoo.io.GrowableByteBuffer;
/**
* Class used for serializing documents on the current head document format.
*
* @author baldersheim
*/
public class VespaDocumentSerializerHead extends VespaDocumentSerializer6 {
public VespaDocumentSerializerHead(GrowableByteBuffer buf) {
super(buf);
}
@Override
public void write(TensorModifyUpdate update) {
putByte(null, (byte) encodeOperationId(update));
if (update.getCreateNonExistingCells()) {
putDouble(null, update.getDefaultCellValue());
}
update.getValue().serialize(this);
}
private int encodeOperationId(TensorModifyUpdate update) {
int operationId = update.getOperation().id;
byte CREATE_FLAG = -0b10000000;
if (update.getCreateNonExistingCells()) {
operationId |= CREATE_FLAG;
}
return operationId;
}
@Override
public void write(TensorAddUpdate update) {
update.getValue().serialize(this);
}
@Override
public void write(TensorRemoveUpdate update) {
update.getValue().serialize(this);
}
}
|