diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-01-19 16:43:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-19 16:43:05 +0100 |
commit | a5df1dfad725b154ceb472c43ae17554dd10b1e9 (patch) | |
tree | 150045267abefc39fe6f920be9ffb4fbf1d9e49c | |
parent | ae55bdddd785fa76b41477330d2b5dd066592a2f (diff) | |
parent | 019ca2a22da2272777db804023203847ef43282e (diff) |
Merge pull request #25630 from vespa-engine/arnej/simplify-document-deserialize
simplify document deserialize
-rw-r--r-- | document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer6.java | 92 |
1 files changed, 20 insertions, 72 deletions
diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer6.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer6.java index a9c3d4804a1..e667739fd50 100644 --- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer6.java +++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer6.java @@ -112,16 +112,18 @@ public class VespaDocumentDeserializer6 extends BufferSerializer implements Docu doc.setId(documentId); if ((content & 0x2) != 0) { - readHeaderBody(doc); + readStruct(doc, doc.getDataType().contentStruct()); + } if ((content & 0x4) != 0) { - readHeaderBody(doc); + readStruct(doc, doc.getDataType().contentStruct()); } if (dataLength != (position() - dataPos)) { throw new DeserializationException("Length mismatch"); } } + public void read(FieldBase field, FieldValue value) { throw new IllegalArgumentException("read not implemented yet."); } @@ -253,100 +255,46 @@ public class VespaDocumentDeserializer6 extends BufferSerializer implements Docu public void read(FieldBase fieldDef, Struct s) { s.setVersion(version); - - if (version < 8) { - throw new DeserializationException("Illegal document serialization version " + version); - } - - int dataSize = getInt(null); - byte ignoredComprCode = getByte(null); - - int numberOfFields = getInt1_4Bytes(null); - - List<Tuple2<Integer, Long>> fieldIdsAndLengths = new ArrayList<>(numberOfFields); - for (int i=0; i<numberOfFields; ++i) { - // id, length (length only used for unknown fields - fieldIdsAndLengths.add(new Tuple2<>(getInt1_4Bytes(null), getInt2_4_8Bytes(null))); - } - - // save a reference to the big buffer we're reading from: - GrowableByteBuffer bigBuf = buf; - GrowableByteBuffer thisStructOnly = GrowableByteBuffer.wrap(getBuf().array(), position(), dataSize); - // set position in original buffer to after data - position(position() + dataSize); - - // for a while: deserialize from this buffer instead: - buf = thisStructOnly; - s.clear(); - StructDataType type = s.getDataType(); - for (int i=0; i<numberOfFields; ++i) { - Field structField = type.getField(fieldIdsAndLengths.get(i).first); - if (structField == null) { - //ignoring unknown field: - position(position() + fieldIdsAndLengths.get(i).second.intValue()); - } else { - int posBefore = position(); - FieldValue value = structField.getDataType().createFieldValue(); - value.deserialize(structField, this); - s.setFieldValue(structField, value); - //jump to beginning of next field: - position(posBefore + fieldIdsAndLengths.get(i).second.intValue()); - } - } - - // restore the original buffer - buf = bigBuf; + readStruct(s, s.getDataType()); } - private void readHeaderBody(Document target) { + private void readStruct(StructuredFieldValue target, StructDataType priType) { if (version < 8) { throw new DeserializationException("Illegal document serialization version " + version); } - int dataSize = getInt(null); byte unusedComprCode = getByte(null); - int numberOfFields = getInt1_4Bytes(null); - List<Tuple2<Integer, Long>> fieldIdsAndLengths = new ArrayList<>(numberOfFields); - for (int i=0; i<numberOfFields; ++i) { - // id, length (length only used for unknown fields - fieldIdsAndLengths.add(new Tuple2<>(getInt1_4Bytes(null), getInt2_4_8Bytes(null))); + var fieldIds = new int[numberOfFields]; + var fieldLens = new int[numberOfFields]; + for (int i = 0; i < numberOfFields; i++) { + fieldIds[i] = getInt1_4Bytes(null); + fieldLens[i] = (int) getInt2_4_8Bytes(null); } - // save a reference to the big buffer we're reading from: - GrowableByteBuffer bigBuf = buf; - GrowableByteBuffer thisStructOnly = GrowableByteBuffer.wrap(getBuf().array(), position(), dataSize); - - // set position in original buffer to after data - position(position() + dataSize); - - // for a while: deserialize from this buffer instead: - buf = thisStructOnly; - - StructDataType priType = target.getDataType().contentStruct(); - - for (int i=0; i<numberOfFields; ++i) { + int afterPos = position() + dataSize; + for (int i = 0; i < numberOfFields; i++) { int posBefore = position(); - Integer f_id = fieldIdsAndLengths.get(i).first; - Field structField = priType.getField(f_id); + Field structField = priType.getField(fieldIds[i]); + // ignoring unknown field if (structField != null) { FieldValue value = structField.getDataType().createFieldValue(); value.deserialize(structField, this); target.setFieldValue(structField, value); } - //jump to beginning of next field: - position(posBefore + fieldIdsAndLengths.get(i).second.intValue()); + // jump to beginning of next field: + position(posBefore + fieldLens[i]); } - - // restore the original buffer - buf = bigBuf; + // set position to after data + position(afterPos); } public void read(FieldBase field, StructuredFieldValue value) { throw new IllegalArgumentException("read not implemented yet."); } + public <T extends FieldValue> void read(FieldBase field, WeightedSet<T> ws) { WeightedSetDataType type = ws.getDataType(); getInt(null); // Have no need for type |