aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/main/java/com/yahoo/document
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahoo-inc.com>2017-01-20 16:56:04 +0100
committerTor Brede Vekterli <vekterli@yahoo-inc.com>2017-01-23 11:18:57 +0100
commit12c42638b7374bfd2f6ce379bf9b8f3986cfe2a2 (patch)
treea82d06089364934edcf80dcc5be87d3893d9a4ab /document/src/main/java/com/yahoo/document
parent4bc7e514ab6e930bc3bf25371eed40cd2dd1264a (diff)
Add binary (de-)serialization of ReferenceFieldValue
Diffstat (limited to 'document/src/main/java/com/yahoo/document')
-rw-r--r--document/src/main/java/com/yahoo/document/Document.java4
-rw-r--r--document/src/main/java/com/yahoo/document/datatypes/ReferenceFieldValue.java4
-rw-r--r--document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java6
-rw-r--r--document/src/main/java/com/yahoo/document/json/JsonWriter.java6
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/FieldReader.java8
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/FieldWriter.java9
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java11
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java12
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/XmlDocumentWriter.java8
9 files changed, 63 insertions, 5 deletions
diff --git a/document/src/main/java/com/yahoo/document/Document.java b/document/src/main/java/com/yahoo/document/Document.java
index e1d912b4e51..798e6004b04 100644
--- a/document/src/main/java/com/yahoo/document/Document.java
+++ b/document/src/main/java/com/yahoo/document/Document.java
@@ -83,7 +83,7 @@ public class Document extends StructuredFieldValue {
private void internalSetId(DocumentId id, DocumentType docType) {
if (id != null && id.hasDocType() && docType != null && !id.getDocType().equals(docType.getName())) {
throw new IllegalArgumentException("Trying to set a document id (type " + id.getDocType() +
- ") that don't match the document type (" + getDataType().getName() + ").");
+ ") that doesn't match the document type (" + getDataType().getName() + ").");
}
docId = id;
}
@@ -113,7 +113,7 @@ public class Document extends StructuredFieldValue {
public void setDataType(DataType type) {
if (docId != null && docId.hasDocType() && !docId.getDocType().equals(type.getName())) {
throw new IllegalArgumentException("Trying to set a document type (" + type.getName() +
- ") that don't match the document id (" + docId + ").");
+ ") that doesn't match the document id (" + docId + ").");
}
super.setDataType(type);
setNewType((DocumentType)type);
diff --git a/document/src/main/java/com/yahoo/document/datatypes/ReferenceFieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/ReferenceFieldValue.java
index 7480d42a405..2a8023099c8 100644
--- a/document/src/main/java/com/yahoo/document/datatypes/ReferenceFieldValue.java
+++ b/document/src/main/java/com/yahoo/document/datatypes/ReferenceFieldValue.java
@@ -94,11 +94,11 @@ public class ReferenceFieldValue extends FieldValue {
@Override
public void serialize(Field field, FieldWriter writer) {
-
+ writer.write(field, this);
}
@Override
public void deserialize(Field field, FieldReader reader) {
-
+ reader.read(field, this);
}
}
diff --git a/document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java b/document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java
index 58b2cac1b17..af156f9dea0 100644
--- a/document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java
+++ b/document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java
@@ -18,6 +18,7 @@ import com.yahoo.document.datatypes.LongFieldValue;
import com.yahoo.document.datatypes.MapFieldValue;
import com.yahoo.document.datatypes.PredicateFieldValue;
import com.yahoo.document.datatypes.Raw;
+import com.yahoo.document.datatypes.ReferenceFieldValue;
import com.yahoo.document.datatypes.StringFieldValue;
import com.yahoo.document.datatypes.Struct;
import com.yahoo.document.datatypes.StructuredFieldValue;
@@ -271,6 +272,11 @@ public class DocumentUpdateJsonSerializer
}
@Override
+ public void write(FieldBase field, ReferenceFieldValue value) {
+ // TODO!
+ }
+
+ @Override
public void write(FieldBase field, Struct value) {
serializeStructField(this, generator, field, value);
}
diff --git a/document/src/main/java/com/yahoo/document/json/JsonWriter.java b/document/src/main/java/com/yahoo/document/json/JsonWriter.java
index 420a6bb6669..734b16253fb 100644
--- a/document/src/main/java/com/yahoo/document/json/JsonWriter.java
+++ b/document/src/main/java/com/yahoo/document/json/JsonWriter.java
@@ -19,6 +19,7 @@ import com.yahoo.document.datatypes.LongFieldValue;
import com.yahoo.document.datatypes.MapFieldValue;
import com.yahoo.document.datatypes.PredicateFieldValue;
import com.yahoo.document.datatypes.Raw;
+import com.yahoo.document.datatypes.ReferenceFieldValue;
import com.yahoo.document.datatypes.StringFieldValue;
import com.yahoo.document.datatypes.Struct;
import com.yahoo.document.datatypes.StructuredFieldValue;
@@ -182,6 +183,11 @@ public class JsonWriter implements DocumentWriter {
}
@Override
+ public void write(FieldBase field, ReferenceFieldValue value) {
+ // TODO!
+ }
+
+ @Override
public void write(FieldBase field, Struct value) {
serializeStructField(this, generator, field, value);
}
diff --git a/document/src/main/java/com/yahoo/document/serialization/FieldReader.java b/document/src/main/java/com/yahoo/document/serialization/FieldReader.java
index d66cf8bb8e1..25b6addcfed 100644
--- a/document/src/main/java/com/yahoo/document/serialization/FieldReader.java
+++ b/document/src/main/java/com/yahoo/document/serialization/FieldReader.java
@@ -126,6 +126,14 @@ public interface FieldReader extends Deserializer {
void read(FieldBase field, TensorFieldValue value);
/**
+ * Read in the value of the given reference field.
+ *
+ * @param field field description (name and data type)
+ * @param value reference field value
+ */
+ void read(FieldBase field, ReferenceFieldValue value);
+
+ /**
* Read in the value of struct field
*
* @param field - field description (name and data type)
diff --git a/document/src/main/java/com/yahoo/document/serialization/FieldWriter.java b/document/src/main/java/com/yahoo/document/serialization/FieldWriter.java
index 244aa0d5a0d..20897f10a67 100644
--- a/document/src/main/java/com/yahoo/document/serialization/FieldWriter.java
+++ b/document/src/main/java/com/yahoo/document/serialization/FieldWriter.java
@@ -14,6 +14,7 @@ import com.yahoo.document.datatypes.LongFieldValue;
import com.yahoo.document.datatypes.MapFieldValue;
import com.yahoo.document.datatypes.PredicateFieldValue;
import com.yahoo.document.datatypes.Raw;
+import com.yahoo.document.datatypes.ReferenceFieldValue;
import com.yahoo.document.datatypes.StringFieldValue;
import com.yahoo.document.datatypes.Struct;
import com.yahoo.document.datatypes.StructuredFieldValue;
@@ -166,6 +167,14 @@ public interface FieldWriter extends Serializer {
void write(FieldBase field, TensorFieldValue value);
/**
+ * Write out the value of the given reference field value.
+ *
+ * @param field field description (name and data type)
+ * @param value reference field value
+ */
+ void write(FieldBase field, ReferenceFieldValue value);
+
+ /**
* Write out the value of struct field
*
* @param field
diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java
index ec0d1bce406..ed1f40e750b 100644
--- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java
+++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java
@@ -37,6 +37,7 @@ import com.yahoo.document.datatypes.LongFieldValue;
import com.yahoo.document.datatypes.MapFieldValue;
import com.yahoo.document.datatypes.PredicateFieldValue;
import com.yahoo.document.datatypes.Raw;
+import com.yahoo.document.datatypes.ReferenceFieldValue;
import com.yahoo.document.datatypes.StringFieldValue;
import com.yahoo.document.datatypes.Struct;
import com.yahoo.document.datatypes.StructuredFieldValue;
@@ -285,6 +286,16 @@ public class VespaDocumentDeserializer42 extends VespaDocumentSerializer42 imple
}
}
+ @Override
+ public void read(FieldBase field, ReferenceFieldValue value) {
+ final boolean documentIdPresent = (buf.get() != 0);
+ if (documentIdPresent) {
+ value.assign(readDocumentId());
+ } else {
+ value.clear();
+ }
+ }
+
public void read(FieldBase fieldDef, Struct s) {
s.setVersion(version);
int startPos = position();
diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java
index a3f1b0a74d4..211412be684 100644
--- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java
+++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java
@@ -278,6 +278,18 @@ public class VespaDocumentSerializer42 extends BufferSerializer implements Docum
}
}
+ @Override
+ public void write(FieldBase field, ReferenceFieldValue value) {
+ if (value.getDocumentId().isPresent()) {
+ // We piggyback on DocumentId's existing serialization code, but need to know
+ // whether or not it's present or merely the empty string.
+ buf.put((byte)1);
+ write(value.getDocumentId().get());
+ } else {
+ buf.put((byte)0);
+ }
+ }
+
/**
* Write out the value of struct field
*
diff --git a/document/src/main/java/com/yahoo/document/serialization/XmlDocumentWriter.java b/document/src/main/java/com/yahoo/document/serialization/XmlDocumentWriter.java
index dc605fbe3d5..16899fa68a4 100644
--- a/document/src/main/java/com/yahoo/document/serialization/XmlDocumentWriter.java
+++ b/document/src/main/java/com/yahoo/document/serialization/XmlDocumentWriter.java
@@ -17,6 +17,7 @@ import com.yahoo.document.datatypes.LongFieldValue;
import com.yahoo.document.datatypes.MapFieldValue;
import com.yahoo.document.datatypes.PredicateFieldValue;
import com.yahoo.document.datatypes.Raw;
+import com.yahoo.document.datatypes.ReferenceFieldValue;
import com.yahoo.document.datatypes.StringFieldValue;
import com.yahoo.document.datatypes.Struct;
import com.yahoo.document.datatypes.StructuredFieldValue;
@@ -37,7 +38,7 @@ import java.util.Map;
/**
* Render a Document instance as XML.
*
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ * @author Steinar Knutsen
*/
@SuppressWarnings("deprecation")
public final class XmlDocumentWriter implements DocumentWriter {
@@ -193,6 +194,11 @@ public final class XmlDocumentWriter implements DocumentWriter {
throw new IllegalArgumentException("write() for tensor field value not implemented yet");
}
+ @Override
+ public void write(FieldBase field, ReferenceFieldValue value) {
+ throw new IllegalArgumentException("write() for reference field value not implemented yet");
+ }
+
private void optionalWrapperStart(FieldBase field) {
if (field == null) {
return;