@ -1470,15 +1470,15 @@ class TextFormat::Printer::TextGenerator
// error.)
bool failed ( ) const { return failed_ ; }
void PrintMaybeWithMarker ( absl : : string_view text ) {
void PrintMaybeWithMarker ( MarkerToken , absl : : string_view text ) override {
Print ( text . data ( ) , text . size ( ) ) ;
if ( ConsumeInsertSilentMarker ( ) ) {
PrintLiteral ( internal : : kDebugStringSilentMarker ) ;
}
}
void PrintMaybeWithMarker ( absl : : string_view text_head ,
absl : : string_view text_tail ) {
void PrintMaybeWithMarker ( MarkerToken , absl : : string_view text_head ,
absl : : string_view text_tail ) override {
Print ( text_head . data ( ) , text_head . size ( ) ) ;
if ( ConsumeInsertSilentMarker ( ) ) {
PrintLiteral ( internal : : kDebugStringSilentMarker ) ;
@ -1577,13 +1577,10 @@ class TextFormat::Printer::DebugStringFieldValuePrinter
void PrintMessageStart ( const Message & /*message*/ , int /*field_index*/ ,
int /*field_count*/ , bool single_line_mode ,
BaseTextGenerator * generator ) const override {
// This is safe as only TextGenerator is used with
// DebugStringFieldValuePrinter.
TextGenerator * text_generator = static_cast < TextGenerator * > ( generator ) ;
if ( single_line_mode ) {
text_ generator- > PrintMaybeWithMarker ( " " , " { " ) ;
generator - > PrintMaybeWithMarker ( MarkerToken ( ) , " " , " { " ) ;
} else {
text_ generator- > PrintMaybeWithMarker ( " " , " { \n " ) ;
generator - > PrintMaybeWithMarker ( MarkerToken ( ) , " " , " { \n " ) ;
}
}
} ;
@ -2174,7 +2171,7 @@ struct FieldIndexSorter {
} // namespace
bool TextFormat : : Printer : : PrintAny ( const Message & message ,
TextGenerator * generator ) const {
Base TextGenerator* generator ) const {
const FieldDescriptor * type_url_field ;
const FieldDescriptor * value_field ;
if ( ! internal : : GetAnyFieldDescriptors ( message , & type_url_field ,
@ -2222,7 +2219,7 @@ bool TextFormat::Printer::PrintAny(const Message& message,
}
void TextFormat : : Printer : : Print ( const Message & message ,
TextGenerator * generator ) const {
Base TextGenerator* generator ) const {
const Reflection * reflection = message . GetReflection ( ) ;
if ( ! reflection ) {
// This message does not provide any way to describe its structure.
@ -2242,10 +2239,20 @@ void TextFormat::Printer::Print(const Message& message,
itr - > second - > Print ( message , single_line_mode_ , generator ) ;
return ;
}
PrintMessage ( message , generator ) ;
}
void TextFormat : : Printer : : PrintMessage ( const Message & message ,
BaseTextGenerator * generator ) const {
if ( generator = = nullptr ) {
return ;
}
const Descriptor * descriptor = message . GetDescriptor ( ) ;
if ( descriptor - > full_name ( ) = = internal : : kAnyFullTypeName & & expand_any_ & &
PrintAny ( message , generator ) ) {
return ;
}
const Reflection * reflection = message . GetReflection ( ) ;
std : : vector < const FieldDescriptor * > fields ;
if ( descriptor - > options ( ) . map_entry ( ) ) {
fields . push_back ( descriptor - > field ( 0 ) ) ;
@ -2460,7 +2467,7 @@ void MapFieldPrinterHelper::CopyValue(const MapValueRef& value,
void TextFormat : : Printer : : PrintField ( const Message & message ,
const Reflection * reflection ,
const FieldDescriptor * field ,
TextGenerator * generator ) const {
Base TextGenerator* generator ) const {
if ( use_short_repeated_primitives_ & & field - > is_repeated ( ) & &
field - > cpp_type ( ) ! = FieldDescriptor : : CPPTYPE_STRING & &
field - > cpp_type ( ) ! = FieldDescriptor : : CPPTYPE_MESSAGE ) {
@ -2508,7 +2515,7 @@ void TextFormat::Printer::PrintField(const Message& message,
printer - > PrintMessageEnd ( sub_message , field_index , count ,
single_line_mode_ , generator ) ;
} else {
generator - > PrintMaybeWithMarker ( " : " ) ;
generator - > PrintMaybeWithMarker ( MarkerToken ( ) , " : " ) ;
// Write the field value.
PrintFieldValue ( message , reflection , field , field_index , generator ) ;
if ( single_line_mode_ ) {
@ -2528,12 +2535,12 @@ void TextFormat::Printer::PrintField(const Message& message,
void TextFormat : : Printer : : PrintShortRepeatedField (
const Message & message , const Reflection * reflection ,
const FieldDescriptor * field , TextGenerator * generator ) const {
const FieldDescriptor * field , Base TextGenerator* generator ) const {
// Print primitive repeated field in short form.
int size = reflection - > FieldSize ( message , field ) ;
PrintFieldName ( message , /*field_index=*/ - 1 , /*field_count=*/ size , reflection ,
field , generator ) ;
generator - > PrintMaybeWithMarker ( " : " , " [ " ) ;
generator - > PrintMaybeWithMarker ( MarkerToken ( ) , " : " , " [ " ) ;
for ( int i = 0 ; i < size ; i + + ) {
if ( i > 0 ) generator - > PrintLiteral ( " , " ) ;
PrintFieldValue ( message , reflection , field , i , generator ) ;
@ -2549,7 +2556,7 @@ void TextFormat::Printer::PrintFieldName(const Message& message,
int field_index , int field_count ,
const Reflection * reflection ,
const FieldDescriptor * field ,
TextGenerator * generator ) const {
Base TextGenerator* generator ) const {
// if use_field_number_ is true, prints field number instead
// of field name.
if ( use_field_number_ ) {
@ -2566,7 +2573,7 @@ void TextFormat::Printer::PrintFieldValue(const Message& message,
const Reflection * reflection ,
const FieldDescriptor * field ,
int index ,
TextGenerator * generator ) const {
Base TextGenerator* generator ) const {
GOOGLE_DCHECK ( field - > is_repeated ( ) | | ( index = = - 1 ) )
< < " Index must be -1 for non-repeated fields " ;
@ -2687,7 +2694,7 @@ void TextFormat::Printer::PrintFieldValue(const Message& message,
}
void TextFormat : : Printer : : PrintUnknownFields (
const UnknownFieldSet & unknown_fields , TextGenerator * generator ,
const UnknownFieldSet & unknown_fields , Base TextGenerator* generator ,
int recursion_budget ) const {
for ( int i = 0 ; i < unknown_fields . field_count ( ) ; i + + ) {
const UnknownField & field = unknown_fields . field ( i ) ;
@ -2696,7 +2703,7 @@ void TextFormat::Printer::PrintUnknownFields(
switch ( field . type ( ) ) {
case UnknownField : : TYPE_VARINT :
generator - > PrintString ( field_number ) ;
generator - > PrintMaybeWithMarker ( " : " ) ;
generator - > PrintMaybeWithMarker ( MarkerToken ( ) , " : " ) ;
generator - > PrintString ( absl : : StrCat ( field . varint ( ) ) ) ;
if ( single_line_mode_ ) {
generator - > PrintLiteral ( " " ) ;
@ -2706,7 +2713,7 @@ void TextFormat::Printer::PrintUnknownFields(
break ;
case UnknownField : : TYPE_FIXED32 : {
generator - > PrintString ( field_number ) ;
generator - > PrintMaybeWithMarker ( " : " , " 0x " ) ;
generator - > PrintMaybeWithMarker ( MarkerToken ( ) , " : " , " 0x " ) ;
generator - > PrintString (
absl : : StrCat ( absl : : Hex ( field . fixed32 ( ) , absl : : kZeroPad8 ) ) ) ;
if ( single_line_mode_ ) {
@ -2718,7 +2725,7 @@ void TextFormat::Printer::PrintUnknownFields(
}
case UnknownField : : TYPE_FIXED64 : {
generator - > PrintString ( field_number ) ;
generator - > PrintMaybeWithMarker ( " : " , " 0x " ) ;
generator - > PrintMaybeWithMarker ( MarkerToken ( ) , " : " , " 0x " ) ;
generator - > PrintString (
absl : : StrCat ( absl : : Hex ( field . fixed64 ( ) , absl : : kZeroPad16 ) ) ) ;
if ( single_line_mode_ ) {
@ -2743,9 +2750,9 @@ void TextFormat::Printer::PrintUnknownFields(
// This field is parseable as a Message.
// So it is probably an embedded message.
if ( single_line_mode_ ) {
generator - > PrintMaybeWithMarker ( " " , " { " ) ;
generator - > PrintMaybeWithMarker ( MarkerToken ( ) , " " , " { " ) ;
} else {
generator - > PrintMaybeWithMarker ( " " , " { \n " ) ;
generator - > PrintMaybeWithMarker ( MarkerToken ( ) , " " , " { \n " ) ;
generator - > Indent ( ) ;
}
PrintUnknownFields ( embedded_unknown_fields , generator ,
@ -2759,7 +2766,7 @@ void TextFormat::Printer::PrintUnknownFields(
} else {
// This field is not parseable as a Message (or we ran out of
// recursion budget). So it is probably just a plain string.
generator - > PrintMaybeWithMarker ( " : " , " \" " ) ;
generator - > PrintMaybeWithMarker ( MarkerToken ( ) , " : " , " \" " ) ;
generator - > PrintString ( absl : : CEscape ( value ) ) ;
if ( single_line_mode_ ) {
generator - > PrintLiteral ( " \" " ) ;
@ -2772,9 +2779,9 @@ void TextFormat::Printer::PrintUnknownFields(
case UnknownField : : TYPE_GROUP :
generator - > PrintString ( field_number ) ;
if ( single_line_mode_ ) {
generator - > PrintMaybeWithMarker ( " " , " { " ) ;
generator - > PrintMaybeWithMarker ( MarkerToken ( ) , " " , " { " ) ;
} else {
generator - > PrintMaybeWithMarker ( " " , " { \n " ) ;
generator - > PrintMaybeWithMarker ( MarkerToken ( ) , " " , " { \n " ) ;
generator - > Indent ( ) ;
}
// For groups, we recurse without checking the budget. This is OK,