-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathproto.gen.h
More file actions
145 lines (132 loc) · 5.22 KB
/
Copy pathproto.gen.h
File metadata and controls
145 lines (132 loc) · 5.22 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2026 Synnax Labs, Inc.
//
// Use of this software is governed by the Business Source License included in the file
// licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with the Business Source
// License, use of this software will be governed by the Apache License, Version 2.0,
// included in the file licenses/APL.txt.
// Code generated by oracle. DO NOT EDIT.
#pragma once
#include <string>
#include <unordered_map>
#include <utility>
#include "client/cpp/channel/json.gen.h"
#include "client/cpp/channel/types.gen.h"
#include "client/cpp/status/json.gen.h"
#include "client/cpp/status/proto.gen.h"
#include "x/cpp/errors/errors.h"
#include "x/cpp/pb/pb.h"
#include "core/pkg/api/channel/pb/channel.pb.h"
#include "core/pkg/service/channel/pb/channel.pb.h"
namespace synnax::channel {
inline std::pair<::service::channel::pb::OperationType, x::errors::Error>
operation_type_to_pb(const std::string &cpp) {
static const std::unordered_map<std::string, ::service::channel::pb::OperationType>
kMap = {
{OPERATION_TYPE_MIN, ::service::channel::pb::OPERATION_TYPE_MIN},
{OPERATION_TYPE_MAX, ::service::channel::pb::OPERATION_TYPE_MAX},
{OPERATION_TYPE_AVG, ::service::channel::pb::OPERATION_TYPE_AVG},
{OPERATION_TYPE_NONE, ::service::channel::pb::OPERATION_TYPE_NONE},
{OPERATION_TYPE_DERIVATIVE,
::service::channel::pb::OPERATION_TYPE_DERIVATIVE},
};
auto it = kMap.find(cpp);
if (it == kMap.end())
return {{}, x::errors::Error("unrecognized OperationType value: " + cpp)};
return {it->second, x::errors::NIL};
}
inline std::pair<std::string, x::errors::Error>
operation_type_from_pb(::service::channel::pb::OperationType pb) {
switch (pb) {
case ::service::channel::pb::OPERATION_TYPE_MIN:
return {OPERATION_TYPE_MIN, x::errors::NIL};
case ::service::channel::pb::OPERATION_TYPE_MAX:
return {OPERATION_TYPE_MAX, x::errors::NIL};
case ::service::channel::pb::OPERATION_TYPE_AVG:
return {OPERATION_TYPE_AVG, x::errors::NIL};
case ::service::channel::pb::OPERATION_TYPE_NONE:
return {OPERATION_TYPE_NONE, x::errors::NIL};
case ::service::channel::pb::OPERATION_TYPE_DERIVATIVE:
return {OPERATION_TYPE_DERIVATIVE, x::errors::NIL};
default:
return {"", x::errors::Error("unrecognized OperationType protobuf value")};
}
}
inline std::pair<::service::channel::pb::Operation, x::errors::Error>
Operation::to_proto() const {
::service::channel::pb::Operation pb;
{
auto [v, err] = operation_type_to_pb(this->type);
if (err) return {{}, err};
pb.set_type(v);
}
pb.set_reset_channel(static_cast<uint32_t>(this->reset_channel));
pb.set_duration(this->duration.to_proto());
return {pb, x::errors::NIL};
}
inline std::pair<Operation, x::errors::Error>
Operation::from_proto(const ::service::channel::pb::Operation &pb) {
Operation cpp;
{
auto [v, err] = operation_type_from_pb(pb.type());
if (err) return {{}, err};
cpp.type = v;
}
cpp.reset_channel = Key(pb.reset_channel());
cpp.duration = ::x::telem::TimeSpan::from_proto(pb.duration());
return {cpp, x::errors::NIL};
}
inline std::pair<::api::channel::pb::Channel, x::errors::Error>
Channel::to_proto() const {
::api::channel::pb::Channel pb;
pb.set_key(static_cast<uint32_t>(this->key));
pb.set_name(this->name);
pb.set_leaseholder(static_cast<uint32_t>(this->leaseholder));
pb.set_data_type(this->data_type.to_proto());
pb.set_is_index(this->is_index);
pb.set_index(static_cast<uint32_t>(this->index));
if (this->alias.has_value()) pb.set_alias(*this->alias);
pb.set_virtual_(this->is_virtual);
pb.set_internal(this->internal);
pb.set_expression(this->expression);
for (const auto &item: this->operations) {
auto [v, err] = item.to_proto();
if (err) return {{}, err};
*pb.add_operations() = v;
}
pb.set_concurrency(static_cast<::x::control::pb::Concurrency>(this->concurrency));
if (this->status.has_value()) {
auto [v, err] = this->status->to_proto();
if (err) return {{}, err};
*pb.mutable_status() = v;
}
return {pb, x::errors::NIL};
}
inline std::pair<Channel, x::errors::Error>
Channel::from_proto(const ::api::channel::pb::Channel &pb) {
Channel cpp;
cpp.key = Key(pb.key());
cpp.name = pb.name();
cpp.leaseholder = ::synnax::cluster::NodeKey(pb.leaseholder());
cpp.data_type = ::x::telem::DataType::from_proto(pb.data_type());
cpp.is_index = pb.is_index();
cpp.index = Key(pb.index());
if (pb.has_alias()) cpp.alias = pb.alias();
cpp.is_virtual = pb.virtual_();
cpp.internal = pb.internal();
cpp.expression = pb.expression();
if (auto err = x::pb::from_proto_repeated<Operation>(
cpp.operations,
pb.operations()
))
return {{}, err};
cpp.concurrency = static_cast<::x::control::Concurrency>(pb.concurrency());
if (pb.has_status()) {
auto [v, err] = Status::from_proto(pb.status());
if (err) return {{}, err};
cpp.status = v;
}
return {cpp, x::errors::NIL};
}
}