summaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java
diff options
context:
space:
mode:
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java19
1 files changed, 17 insertions, 2 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java b/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java
index 8ab23c8d77c..6b0443c9bfe 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java
@@ -53,8 +53,15 @@ class SparseBinaryFormat implements BinaryFormat {
}
@Override
- public Tensor decode(TensorType type, GrowableByteBuffer buffer) {
- consumeAndValidateDimensions(type, buffer);
+ public Tensor decode(Optional<TensorType> optionalType, GrowableByteBuffer buffer) {
+ TensorType type;
+ if (optionalType.isPresent()) {
+ type = optionalType.get();
+ consumeAndValidateDimensions(optionalType.get(), buffer);
+ }
+ else {
+ type = decodeType(buffer);
+ }
Tensor.Builder builder = Tensor.Builder.of(type);
decodeCells(buffer, builder, type);
return builder.build();
@@ -75,6 +82,14 @@ class SparseBinaryFormat implements BinaryFormat {
}
}
+ private TensorType decodeType(GrowableByteBuffer buffer) {
+ int numDimensions = buffer.getInt1_4Bytes();
+ TensorType.Builder builder = new TensorType.Builder();
+ for (int i = 0; i < numDimensions; ++i)
+ builder.mapped(buffer.getUtf8String());
+ return builder.build();
+ }
+
private void decodeCells(GrowableByteBuffer buffer, Tensor.Builder builder, TensorType type) {
int numCells = buffer.getInt1_4Bytes();
for (int i = 0; i < numCells; ++i) {