1 #include "google/protobuf/unredacted_debug_format_for_test.h" 2 3 #include <string> 4 5 #include "google/protobuf/message.h" 6 #include "google/protobuf/message_lite.h" 7 #include "google/protobuf/text_format.h" 8 9 namespace google { 10 namespace protobuf { 11 namespace util { 12 UnredactedDebugFormatForTest(const google::protobuf::Message & message)13std::string UnredactedDebugFormatForTest(const google::protobuf::Message& message) { 14 std::string debug_string; 15 16 google::protobuf::TextFormat::Printer printer; 17 printer.SetExpandAny(true); 18 printer.SetReportSensitiveFields( 19 internal::FieldReporterLevel::kUnredactedDebugFormatForTest); 20 21 printer.PrintToString(message, &debug_string); 22 23 return debug_string; 24 } 25 UnredactedShortDebugFormatForTest(const google::protobuf::Message & message)26std::string UnredactedShortDebugFormatForTest(const google::protobuf::Message& message) { 27 std::string debug_string; 28 29 google::protobuf::TextFormat::Printer printer; 30 printer.SetSingleLineMode(true); 31 printer.SetExpandAny(true); 32 printer.SetReportSensitiveFields( 33 internal::FieldReporterLevel::kUnredactedShortDebugFormatForTest); 34 35 printer.PrintToString(message, &debug_string); 36 // Single line mode currently might have an extra space at the end. 37 if (!debug_string.empty() && debug_string[debug_string.size() - 1] == ' ') { 38 debug_string.resize(debug_string.size() - 1); 39 } 40 41 return debug_string; 42 } 43 UnredactedUtf8DebugFormatForTest(const google::protobuf::Message & message)44std::string UnredactedUtf8DebugFormatForTest(const google::protobuf::Message& message) { 45 std::string debug_string; 46 47 google::protobuf::TextFormat::Printer printer; 48 printer.SetUseUtf8StringEscaping(true); 49 printer.SetExpandAny(true); 50 printer.SetReportSensitiveFields( 51 internal::FieldReporterLevel::kUnredactedUtf8DebugFormatForTest); 52 53 printer.PrintToString(message, &debug_string); 54 55 return debug_string; 56 } 57 UnredactedDebugFormatForTest(const google::protobuf::MessageLite & message)58std::string UnredactedDebugFormatForTest(const google::protobuf::MessageLite& message) { 59 return message.DebugString(); 60 } 61 UnredactedShortDebugFormatForTest(const google::protobuf::MessageLite & message)62std::string UnredactedShortDebugFormatForTest( 63 const google::protobuf::MessageLite& message) { 64 return message.ShortDebugString(); 65 } 66 UnredactedUtf8DebugFormatForTest(const google::protobuf::MessageLite & message)67std::string UnredactedUtf8DebugFormatForTest( 68 const google::protobuf::MessageLite& message) { 69 return message.Utf8DebugString(); 70 } 71 72 } // namespace util 73 } // namespace protobuf 74 } // namespace google 75