-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbtrdb_util.cpp
More file actions
64 lines (51 loc) · 1.86 KB
/
btrdb_util.cpp
File metadata and controls
64 lines (51 loc) · 1.86 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "btrdb_util.h"
#include <sstream>
#include <grpc++/grpc++.h>
namespace btrdb {
std::vector<std::string> split_string(const std::string& str, char delimiter) {
std::vector<std::string> parts;
std::istringstream input(str);
std::string part;
while (std::getline(input, part, delimiter)) {
parts.push_back(part);
}
return parts;
}
Status::Status() : type_(Status::Type::StatusOK), code_(0), message_() {}
Status::Status(const grpc::Status& grpcstatus)
: type_(Status::Type::GRPCError), code_(0),
message_(grpcstatus.error_message()) {}
Status::Status(std::uint32_t code, std::string message)
: type_(Status::Type::CodedError), code_(code), message_(message) {
if (code == 0) {
type_ = Status::Type::StatusOK;
}
}
Status::Status(const grpcinterface::Status& btrdbstatus)
: Status(btrdbstatus.code(), btrdbstatus.msg()) {}
bool Status::isError() const {
return this->type_ != Status::Type::StatusOK;
}
std::uint32_t Status::code() const {
return this->code_;
}
std::string Status::message() const {
std::ostringstream output;
switch (this->type_) {
case Status::Type::StatusOK:
output << "Success";
break;
case Status::Type::GRPCError:
output << "grpc: " << this->message_;
break;
case Status::Type::CodedError:
output << "[" << this->code_ << "] " << this->message_;
break;
}
return output.str();
}
const Status Status::ClusterDegraded(419, "Cluster is degraded");
const Status Status::NoSuchStream(404, "No such stream");
const Status Status::WrongArgs(421, "Invalid arguments");
const Status Status::Disconnected(421, "Driver is disconnected");
}