Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions olp-cpp-sdk-dataservice-read/src/generated/api/BlobApi.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2024 HERE Europe B.V.
* Copyright (C) 2019-2026 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,10 +22,9 @@
#include <cstring>
#include <map>
#include <memory>
#include <mutex>
#include <unordered_map>

#include <olp/core/client/OlpClient.h>
#include <olp/core/utils/Url.h>

namespace olp {
namespace dataservice {
Expand Down Expand Up @@ -55,7 +54,7 @@ BlobApi::DataResponse BlobApi::GetBlob(

// In case we know the size in advance, we should pre-allocated a buffer.
const auto expected_size = partition.GetDataSize();
const auto kPartitionPreallocateLimit = 10 * 1024 * 1024;
constexpr auto kPartitionPreallocateLimit = 10 * 1024 * 1024;
if (expected_size && *expected_size > 0 &&
*expected_size < kPartitionPreallocateLimit) {
buffer.reserve(*expected_size);
Expand Down Expand Up @@ -84,6 +83,51 @@ BlobApi::DataResponse BlobApi::GetBlob(
return {std::make_shared<std::vector<unsigned char>>(std::move(buffer)),
api_response.GetNetworkStatistics()};
}

BlobApi::DataResponse BlobApi::GetBlobByKey(
const client::OlpClient& client, const std::string& layer_id,
const std::string& key, porting::optional<std::string> billing_tag,
porting::optional<std::string> range,
const client::CancellationContext& context) {
std::multimap<std::string, std::string> header_params;
header_params.emplace("Accept", "application/octet-stream");
if (range) {
header_params.emplace("Range", *range);
}

std::multimap<std::string, std::string> query_params;
if (billing_tag) {
query_params.emplace("billingTag", *billing_tag);
}

std::string metadata_uri =
"/layers/" + layer_id + "/keys/" + olp::utils::Url::Encode(key);

std::vector<unsigned char> buffer;

auto data_callback = [&](const std::uint8_t* data, const std::uint64_t offset,
const std::size_t length) {
if (!offset) {
buffer.clear();
}

const auto buffer_size = buffer.size();
buffer.resize(buffer_size + length);
std::memcpy(buffer.data() + buffer_size, data, length);
};

auto api_response =
client.CallApiStream(metadata_uri, "GET", query_params, header_params,
data_callback, nullptr, "", context);

if (api_response.GetStatus() != http::HttpStatusCode::OK) {
return {client::ApiError(api_response.GetStatus()),
api_response.GetNetworkStatistics()};
}

return {std::make_shared<std::vector<unsigned char>>(std::move(buffer)),
api_response.GetNetworkStatistics()};
}
} // namespace read
} // namespace dataservice
} // namespace olp
28 changes: 27 additions & 1 deletion olp-cpp-sdk-dataservice-read/src/generated/api/BlobApi.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2024 HERE Europe B.V.
* Copyright (C) 2019-2026 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -71,6 +71,32 @@ class BlobApi {
porting::optional<std::string> billing_tag,
porting::optional<std::string> range,
const client::CancellationContext& context);

/**
* @brief Retrieves a plain data blob for the specified layer and key.
* @param client Instance of OlpClient used to make REST request.
* @param layer_id Layer id.
* @param key The key of the blob to be retrieved.
* @param billing_tag An optional free-form tag which is used for grouping
* billing records together. If supplied, it must be between 4 - 16
* characters, contain only alpha/numeric ASCII characters [A-Za-z0-9].
* @param range Use this parameter to resume download of a large response
* when there is a connection issue between the client and server.
* Specify a single byte range offset like this: Range: bytes=10-.
* This parameter is compliant with RFC 7233, but note that this parameter
* only supports a single byte range. The range parameter can also be
* specified as a query parameter, i.e. range=bytes=10-.
* @param context A CancellationContext, which can be used to cancel the
* pending request.
*
* @return Data response.
*/
static DataResponse GetBlobByKey(const client::OlpClient& client,
const std::string& layer_id,
const std::string& key,
porting::optional<std::string> billing_tag,
porting::optional<std::string> range,
const client::CancellationContext& context);
};

} // namespace read
Expand Down
Loading
Loading