summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-03-28 22:33:57 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2017-03-28 22:33:57 +0200
commit50339677e91f92ef2ea72ce88627dc1402c275da (patch)
tree25d15750727409caca3a13e2982e5f2fb0ab5979 /document
parentddf9abb798e3f6169ba9d04e5025eb4fa1cfe2e6 (diff)
Move the hasBodyField check to a common place so it is used consistently.
Diffstat (limited to 'document')
-rw-r--r--document/src/vespa/document/fieldvalue/document.cpp18
-rw-r--r--document/src/vespa/document/fieldvalue/document.h1
2 files changed, 17 insertions, 2 deletions
diff --git a/document/src/vespa/document/fieldvalue/document.cpp b/document/src/vespa/document/fieldvalue/document.cpp
index 5535ba659ec..f8358cfb544 100644
--- a/document/src/vespa/document/fieldvalue/document.cpp
+++ b/document/src/vespa/document/fieldvalue/document.cpp
@@ -379,9 +379,23 @@ void Document::serializeBody(ByteBuffer& buffer) const {
buffer.putBytes(stream.peek(), stream.size());
}
+bool Document::hasBodyField() const {
+ for (document::StructuredFieldValue::const_iterator it(getFields().begin()), mt(getFields().end());
+ it != mt;
+ ++it)
+ {
+ if ( ! it.field().isHeaderField() ) {
+ return true;
+ }
+ }
+ return false;
+}
+
void Document::serializeBody(nbostream& stream) const {
- VespaDocumentSerializer serializer(stream);
- serializer.write(_fields, BodyFields());
+ if (hasBodyField()) {
+ VespaDocumentSerializer serializer(stream);
+ serializer.write(_fields, BodyFields());
+ }
}
void Document::deserialize(const DocumentTypeRepo& repo, vespalib::nbostream & os) {
diff --git a/document/src/vespa/document/fieldvalue/document.h b/document/src/vespa/document/fieldvalue/document.h
index e25f3b1dc2f..46bf655d971 100644
--- a/document/src/vespa/document/fieldvalue/document.h
+++ b/document/src/vespa/document/fieldvalue/document.h
@@ -150,6 +150,7 @@ public:
void setFieldValue(const Field& field, FieldValue::UP data) override;
private:
+ bool hasBodyField() const;
bool hasFieldValue(const Field& field) const override { return _fields.hasValue(field); }
void removeFieldValue(const Field& field) override { _fields.remove(field); }
FieldValue::UP getFieldValue(const Field& field) const override { return _fields.getValue(field); }