Skip to content

Commit

Permalink
Refactored operation id (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gazizonoki authored Sep 3, 2024
1 parent d36a9a1 commit 5b7141a
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 115 deletions.
37 changes: 18 additions & 19 deletions include/ydb-cpp-sdk/library/operation_id/operation_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
#include <memory>
#include <string>
#include <vector>
#include <unordered_map>

namespace Ydb {
class TOperationId;
}

namespace NKikimr {
namespace NOperationId {

class TOperationId {
static constexpr int kEKindMinValue = 0;
static constexpr int kEKindMaxValue = 10;
public:
enum EKind : int {
UNUSED = 0,
Expand All @@ -31,40 +32,38 @@ class TOperationId {
std::string Value;
};

using TDataList = std::vector<std::unique_ptr<TData>>;

TOperationId();
explicit TOperationId(const std::string& string, bool allowEmpty = false);

TOperationId(const TOperationId& other);
TOperationId(TOperationId&& other) = default;
TOperationId(TOperationId&& other);

TOperationId& operator=(const TOperationId& other);
TOperationId& operator=(TOperationId&& other) = default;
TOperationId& operator=(TOperationId&& other);

~TOperationId() = default;
~TOperationId();

EKind GetKind() const;
void SetKind(const EKind& kind);

const TDataList& GetData() const;
TDataList& GetMutableData();
std::vector<TData> GetData() const;

void AddOptionalValue(const std::string& key, const std::string& value);
const std::vector<const std::string*>& GetValue(const std::string& key) const;

std::string GetSubKind() const;
std::string ToString() const;

const Ydb::TOperationId& GetProto() const;
private:
bool IsValidKind(int kind);
void CopyData(const TOperationId::TDataList& otherData);

EKind Kind;
TDataList Data;
std::unordered_map<std::string, std::vector<const std::string*>> Index;
class TImpl;
std::unique_ptr<TImpl> Impl;
};

void AddOptionalValue(TOperationId& operarionId, const std::string& key, const std::string& value);
void AddOptionalValue(TOperationId& operarionId, const std::string& key, const char* value, size_t size);
std::string ProtoToString(const Ydb::TOperationId& proto);

void AddOptionalValue(Ydb::TOperationId& operarionId, const std::string& key, const std::string& value);

TOperationId::EKind ParseKind(const std::string_view value);

std::string FormatPreparedQueryIdCompat(const std::string& str);
Expand Down
3 changes: 3 additions & 0 deletions src/library/operation_id/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
add_subdirectory(protos)

_ydb_sdk_add_library(library-operation_id)

target_link_libraries(library-operation_id
PRIVATE
yutil
cgiparam
uri
lib-operation_id-protos
)

target_sources(library-operation_id PRIVATE
Expand Down
Loading

0 comments on commit 5b7141a

Please sign in to comment.