35std::vector<int> SortProtobufMapByKeys(
36 const google::protobuf::Message& message,
37 const google::protobuf::FieldDescriptor* field,
38 const google::protobuf::Reflection& reflection,
const int size) {
39 std::vector<int> output;
43 if (field->cpp_type() == google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE) {
44 const ::google::protobuf::Message& item =
45 reflection.GetRepeatedMessage(message, field, 0);
46 const ::google::protobuf::FieldDescriptor* item_fd =
47 item.GetDescriptor()->FindFieldByName(
"key");
48 if (item_fd && field->is_map() &&
49 ::google::protobuf::FieldDescriptor::Type::TYPE_STRING ==
51 std::vector<std::pair<std::string, int>> key_indices;
52 key_indices.reserve(size);
53 for (
int i = 0; i < size; ++i) {
54 const ::google::protobuf::Message& item =
55 reflection.GetRepeatedMessage(message, field, i);
56 const ::google::protobuf::FieldDescriptor* item_fd =
57 item.GetDescriptor()->FindFieldByName(
"key");
58 const std::string key(item.GetReflection()->GetString(item, item_fd));
59 key_indices.emplace_back(key, i);
61 std::sort(key_indices.begin(), key_indices.end());
63 for (
const std::pair<std::string, int>& key_index : key_indices) {
64 output.push_back(key_index.second);
71 std::iota(output.begin(), output.end(), 0);
78 const google::protobuf::Message* msg,
79 const google::protobuf::Reflection* reflection,
80 const google::protobuf::FieldDescriptor* field)
86 reflection_ptr_(reflection) {}
105 std::ostringstream out_str;
109 s->
AddStr(out_str.str().c_str());
113 auto channel_msg = channel_msg_ptr->CopyMsgPtr();
114 if (!channel_msg_ptr->raw_msg_class_->ParseFromString(
115 channel_msg->message)) {
117 "Cannot Parse the message for Real-Time Updating");
121 if (message_ptr_ && reflection_ptr_) {
123 if (field_->is_repeated()) {
124 size = reflection_ptr_->FieldSize(*message_ptr_, field_);
126 if (reflection_ptr_->HasField(*message_ptr_, field_) ||
127 field_->containing_type()->options().map_entry()) {
132 if (size <= item_index_) {
134 out_str <<
"The item [" << item_index_ <<
"] has been empty !!!";
140 is_folded_ = !is_folded_;
141 }
else if (is_folded_) {
146 if (item_index_ >= size) {
154 if (item_index_ < 0) {
155 item_index_ = size - 1;
165 reflection_ptr_, is_folded_);
173 const std::vector<int> indices(
174 SortProtobufMapByKeys(*message_ptr_, field_, *reflection_ptr_, size));
177 &
line_no, 0, reflection_ptr_, field_,
178 indices[item_index_]);
180 for (
const int index : indices) {
182 &
line_no, 0, reflection_ptr_, field_,
const std::string & message_type(void) const
double frame_ratio(void) override
std::string GetChannelName(void) const
static void PrintField(GeneralMessageBase *baseMsg, const google::protobuf::Message &msg, int *jump_lines, const Screen *s, int *line_no, int indent, const google::protobuf::Reflection *ref, const google::protobuf::FieldDescriptor *field, int index)
static int LineCountOfField(const google::protobuf::Message &msg, int screen_width, const google::protobuf::FieldDescriptor *field, const google::protobuf::Reflection *reflection, bool is_folded=true)
GeneralMessage(GeneralMessageBase *parent, const google::protobuf::Message *msg, const google::protobuf::Reflection *reflection, const google::protobuf::FieldDescriptor *field)
int Render(const Screen *s, int key) override
RenderableMessage * parent(void) const
static constexpr int FrameRatio_Precision
void AddStr(int x, int y, ColorPair color, const char *str) const
void SetCurrentColor(ColorPair color) const
void ClearCurrentColor(void) const