summaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/tensor/tensor_deserialize.cpp
blob: a8399d9ddeb2b619444c10fe443a2c1900a169a3 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "tensor_deserialize.h"
#include <vespa/document/util/serializableexceptions.h>
#include <vespa/eval/eval/fast_value.h>
#include <vespa/eval/eval/value_codec.h>
#include <vespa/eval/eval/value.h>

using document::DeserializeException;
using vespalib::eval::FastValueBuilderFactory;
using vespalib::eval::Value;

namespace search::tensor {

std::unique_ptr<Value> deserialize_tensor(vespalib::nbostream &buffer)
{
    try {
        auto tensor = vespalib::eval::decode_value(buffer, FastValueBuilderFactory::get());
        if (buffer.size() != 0) {
            throw DeserializeException("Leftover bytes deserializing tensor attribute value.", VESPA_STRLOC);
        }
        return tensor;
    } catch (const vespalib::eval::DecodeValueException &e) {
        throw DeserializeException("tensor value decode failed", e, VESPA_STRLOC);
    }
}

std::unique_ptr<Value> deserialize_tensor(const void *data, size_t size)
{
    vespalib::nbostream wrapStream(data, size);
    return deserialize_tensor(wrapStream);
}

} // namespace