6 namespace gp = google::protobuf;
9 const gp::FileDescriptorSet& descriptor_set,
13 gp::FileDescriptorProto unused;
15 for (
int i = 0; i < descriptor_set.file_size(); ++i)
17 const auto&
file = descriptor_set.file(i);
18 if (!_proto_database.FindFileByName(
file.name(), &unused))
20 if (!_proto_database.Add(file))
22 throw std::runtime_error(
28 _msg_descriptor = _proto_pool.FindMessageTypeByName(
type_name);
30 if (_msg_descriptor ==
nullptr)
32 throw std::runtime_error(
"Cannot get message descriptor");
38 const google::protobuf::Message* prototype_msg =
41 google::protobuf::Message* mutable_msg = prototype_msg->New();
42 if (!mutable_msg->ParseFromArray(serialized_msg.
data(), serialized_msg.
size()))
47 std::function<
void(
const google::protobuf::Message&,
const std::string&,
const bool)>
50 ParseImpl = [&](
const google::protobuf::Message&
msg,
const std::string& prefix,
52 const gp::Reflection* reflection =
msg.GetReflection();
53 const gp::Descriptor* descriptor =
msg.GetDescriptor();
57 for (
int index = 0; index < descriptor->field_count(); index++)
59 auto field = descriptor->field(index);
68 if (
field->name() ==
"key")
86 bool repeated =
false;
87 if (
field->is_repeated())
105 for (
unsigned index = 0; index <
count; index++)
112 bool is_double =
true;
114 switch (
field->cpp_type())
116 case gp::FieldDescriptor::CPPTYPE_DOUBLE: {
117 value = !repeated ? reflection->GetDouble(
msg,
field) :
118 reflection->GetRepeatedDouble(
msg,
field, index);
121 case gp::FieldDescriptor::CPPTYPE_FLOAT: {
122 auto tmp = !repeated ? reflection->GetFloat(
msg,
field) :
123 reflection->GetRepeatedFloat(
msg,
field, index);
124 value =
static_cast<double>(tmp);
127 case gp::FieldDescriptor::CPPTYPE_UINT32: {
128 auto tmp = !repeated ? reflection->GetUInt32(
msg,
field) :
129 reflection->GetRepeatedUInt32(
msg,
field, index);
130 value =
static_cast<double>(tmp);
133 case gp::FieldDescriptor::CPPTYPE_UINT64: {
134 auto tmp = !repeated ? reflection->GetUInt64(
msg,
field) :
135 reflection->GetRepeatedUInt64(
msg,
field, index);
136 value =
static_cast<double>(tmp);
139 case gp::FieldDescriptor::CPPTYPE_BOOL: {
140 auto tmp = !repeated ? reflection->GetBool(
msg,
field) :
141 reflection->GetRepeatedBool(
msg,
field, index);
142 value =
static_cast<double>(tmp);
145 case gp::FieldDescriptor::CPPTYPE_INT32: {
146 auto tmp = !repeated ? reflection->GetInt32(
msg,
field) :
147 reflection->GetRepeatedInt32(
msg,
field, index);
148 value =
static_cast<double>(tmp);
151 case gp::FieldDescriptor::CPPTYPE_INT64: {
152 auto tmp = !repeated ? reflection->GetInt64(
msg,
field) :
153 reflection->GetRepeatedInt64(
msg,
field, index);
154 value =
static_cast<double>(tmp);
157 case gp::FieldDescriptor::CPPTYPE_ENUM: {
158 auto tmp = !repeated ? reflection->GetEnum(
msg,
field) :
159 reflection->GetRepeatedEnum(
msg,
field, index);
162 series.pushBack({ timestamp, tmp->name() });
166 case gp::FieldDescriptor::CPPTYPE_STRING: {
167 auto tmp = !repeated ? reflection->GetString(
msg,
field) :
168 reflection->GetRepeatedString(
msg,
field, index);
170 if (tmp.size() > 100)
176 series.pushBack({ timestamp, tmp });
180 case gp::FieldDescriptor::CPPTYPE_MESSAGE: {
182 #pragma push_macro("GetMessage")
184 const auto& new_msg = repeated ?
185 reflection->GetRepeatedMessage(
msg,
field, index) :
187 #pragma pop_macro("GetMessage")
192 const auto* map_descriptor = new_msg.GetDescriptor();
193 const auto* map_reflection = new_msg.GetReflection();
194 const auto* key_field = map_descriptor->FindFieldByName(
"key");
195 switch (key_field->cpp_type())
198 case gp::FieldDescriptor::CPPTYPE_STRING: {
200 fmt::format(
"/{}", map_reflection->GetString(new_msg, key_field));
203 case gp::FieldDescriptor::CPPTYPE_INT32: {
205 fmt::format(
"/{}", map_reflection->GetInt32(new_msg, key_field));
208 case gp::FieldDescriptor::CPPTYPE_INT64: {
210 fmt::format(
"/{}", map_reflection->GetInt64(new_msg, key_field));
213 case gp::FieldDescriptor::CPPTYPE_UINT32: {
215 fmt::format(
"/{}", map_reflection->GetUInt32(new_msg, key_field));
218 case gp::FieldDescriptor::CPPTYPE_UINT64: {
220 fmt::format(
"/{}", map_reflection->GetUInt64(new_msg, key_field));
225 ParseImpl(new_msg, key + suffix,
field->is_map());
234 auto& series = this->
getSeries(key + suffix);
235 series.pushBack({ timestamp, value });