blob: 92bce41ba8cbca3d919239b2ccec761d4656df1e (
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Copyright 2017 Yahoo Holdings. 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.DocumentUpdate;
import com.yahoo.document.datatypes.ByteFieldValue;
import com.yahoo.document.fieldpathupdate.AddFieldPathUpdate;
import com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate;
import com.yahoo.document.fieldpathupdate.FieldPathUpdate;
import com.yahoo.document.update.FieldUpdate;
import com.yahoo.io.GrowableByteBuffer;
import com.yahoo.vespa.objects.FieldBase;
/**
* Class used for serializing documents on the current head document format.
*
* @author baldersheim
*/
@SuppressWarnings("deprecation")
public class VespaDocumentSerializerHead extends VespaDocumentSerializer42 {
public VespaDocumentSerializerHead(GrowableByteBuffer buf) {
super(buf);
}
@Override
public void write(DocumentUpdate update) {
update.getId().serialize(this);
update.getDocumentType().serialize(this);
putInt(null, update.fieldUpdates().size());
for (FieldUpdate up : update.fieldUpdates()) {
up.serialize(this);
}
DocumentUpdateFlags flags = new DocumentUpdateFlags();
flags.setCreateIfNonExistent(update.getCreateIfNonExistent());
putInt(null, flags.injectInto(update.fieldPathUpdates().size()));
for (FieldPathUpdate up : update.fieldPathUpdates()) {
up.serialize(this);
}
}
public void write(FieldPathUpdate update) {
putByte(null, (byte)update.getUpdateType().getCode());
put(null, update.getOriginalFieldPath());
put(null, update.getOriginalWhereClause());
}
public void write(AssignFieldPathUpdate update) {
write((FieldPathUpdate)update);
byte flags = 0;
if (update.getRemoveIfZero()) {
flags |= AssignFieldPathUpdate.REMOVE_IF_ZERO;
}
if (update.getCreateMissingPath()) {
flags |= AssignFieldPathUpdate.CREATE_MISSING_PATH;
}
if (update.isArithmetic()) {
flags |= AssignFieldPathUpdate.ARITHMETIC_EXPRESSION;
putByte(null, flags);
put(null, update.getExpression());
} else {
putByte(null, flags);
update.getFieldValue().serialize(this);
}
}
public void write(AddFieldPathUpdate update) {
write((FieldPathUpdate)update);
update.getNewValues().serialize(this);
}
@Override
public void write(FieldBase field, ByteFieldValue value) {
buf.put(value.getByte());
}
}
|