* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#ifndef FLINK_BENCHMARK_KEYVALUEBYTECONTAINER_H
#define FLINK_BENCHMARK_KEYVALUEBYTECONTAINER_H
#include <vector>
#include <memory>
#include <stdexcept>
#include <cstdint>
#include <libboundscheck/include/securec.h>
class KeyValueByteContainer {
public:
char* key;
char* value;
size_t keyLen;
size_t valueLen;
KeyValueByteContainer() = default;
KeyValueByteContainer(char* keyData, std::string_view valueData) : key(keyData)
{
valueLen = valueData.size();
value = reinterpret_cast<char*>(malloc(valueLen));
if (!value) {
throw std::runtime_error("allocate memory failed!");
}
memcpy_s(value, valueLen, valueData.data(), valueLen);
}
~KeyValueByteContainer()
{
}
[[nodiscard]] size_t keySize() const noexcept
{
return strlen(value);
}
[[nodiscard]] size_t valueSize() const noexcept
{
return valueLen;
}
};
#endif