186 {
187 std::ostringstream out_str;
188 std::ios_base::fmtflags old_flags;
189
190 switch (field->cpp_type()) {
191#define OUTPUT_FIELD(CPPTYPE, METHOD, PRECISION) \
192 case google::protobuf::FieldDescriptor::CPPTYPE_##CPPTYPE: \
193 if (*jump_lines) { \
194 --(*jump_lines); \
195 } else { \
196 const std::string& fieldName = field->name(); \
197 out_str << fieldName << ": "; \
198 if (field->is_repeated()) { \
199 out_str << "[" << index << "] "; \
200 } \
201 old_flags = out_str.flags(); \
202 out_str << std::fixed << std::setprecision(PRECISION) \
203 << (field->is_repeated() \
204 ? ref->GetRepeated##METHOD(msg, field, index) \
205 : ref->Get##METHOD(msg, field)); \
206 out_str.flags(old_flags); \
207 s->AddStr(indent, (*line_no)++, out_str.str().c_str()); \
208 } \
209 break
210
218#undef OUTPUT_FIELD
219
220 case google::protobuf::FieldDescriptor::CPPTYPE_STRING: {
221 std::string scratch;
222 const std::string& str =
223 field->is_repeated()
224 ? ref->GetRepeatedStringReference(msg, field, index, &scratch)
225 : ref->GetStringReference(msg, field, &scratch);
226 {
227 int line_width = 0;
228 std::size_t i = 0;
229
230 for (; i < str.size() && *jump_lines > 0; ++i) {
231 if (str[i] == '\n' || str[i] == '\r') {
232 --(*jump_lines);
233 line_width = 0;
234 } else {
235 ++line_width;
236 if (line_width == s->
Width()) {
237 --(*jump_lines);
238 line_width = 0;
239 }
240 }
241 }
242
243 if (*jump_lines == 0) {
244 line_width = 0;
245 unsigned line_count = 1;
246
247 const std::string& fieldName = field->name();
248 out_str << fieldName << ": ";
249 if (field->is_repeated()) {
250 out_str << "[" << index << "] ";
251 }
252
253 for (; i < str.size(); ++i) {
254 char ch = str[i];
255 if (str[i] == '\n' || str[i] == '\r') {
256 ++line_count;
257 line_width = 0;
258 ch = '\n';
259 } else {
260 ++line_width;
261 if (line_width == s->
Width()) {
262 ++line_count;
263 line_width = 0;
264 }
265 }
266 out_str << ch;
267 }
268
270 (*line_no) += line_count;
271 }
272 }
273
274 break;
275 }
276
277 case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: {
278 if (*jump_lines) {
279 --(*jump_lines);
280 } else {
281 const std::string& fieldName = field->name();
282 out_str << fieldName << ": ";
283 if (field->is_repeated()) {
284 out_str << "[" << index << "] ";
285 }
286 int enum_value = field->is_repeated()
287 ? ref->GetRepeatedEnumValue(msg, field, index)
288 : ref->GetEnumValue(msg, field);
289 const google::protobuf::EnumValueDescriptor* enum_desc =
290 field->enum_type()->FindValueByNumber(enum_value);
291 if (enum_desc != nullptr) {
292 out_str << enum_desc->name();
293 } else {
294 out_str << enum_value;
295 }
297 }
298 break;
299 }
300
301 case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE:
302 if (!*jump_lines) {
303 const std::string& fieldName = field->name();
304 out_str << fieldName;
305 if (!field->is_map()) {
306 out_str << ": ";
307 if (field->is_repeated()) {
308 out_str << "[" << index << "] ";
309 }
310 }
312 } else {
313 --(*jump_lines);
314 }
316 baseMsg,
317 field->is_repeated() ? ref->GetRepeatedMessage(msg, field, index)
318 : ref->GetMessage(msg, field),
319 jump_lines, s,
line_no, indent + 2);
320 break;
321 }
322}
static void PrintMessage(GeneralMessageBase *baseMsg, const google::protobuf::Message &msg, int *jump_lines, const Screen *s, int *line_no, int indent)
void AddStr(int x, int y, ColorPair color, const char *str) const
#define OUTPUT_FIELD(CPPTYPE, METHOD, PRECISION)