Skip to content

Commit

Permalink
Disable useShortRepeatedPrimitives for Printer.DEFAULT_DEBUG_FORMAT
Browse files Browse the repository at this point in the history
In addition, this change refactors DebugFormat so that it now uses Printer.DEFAULT_DEBUG_FORMAT.

PiperOrigin-RevId: 707623592
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Dec 18, 2024
1 parent 880d2b0 commit 1900cbe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 14 additions & 9 deletions java/core/src/main/java/com/google/protobuf/DebugFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,30 @@ public static DebugFormat multiline() {
}

public String toString(MessageOrBuilder message) {
return TextFormat.printer()
if (!this.isSingleLine) {
return TextFormat.debugFormatPrinter()
.printToString(message, TextFormat.Printer.FieldReporterLevel.DEBUG_MULTILINE);
}
return TextFormat.debugFormatPrinter()
.emittingSingleLine(this.isSingleLine)
.enablingSafeDebugFormat(true)
.printToString(message, this.isSingleLine
? TextFormat.Printer.FieldReporterLevel.DEBUG_SINGLE_LINE
: TextFormat.Printer.FieldReporterLevel.DEBUG_MULTILINE);
.printToString(message, TextFormat.Printer.FieldReporterLevel.DEBUG_SINGLE_LINE);
}

public String toString(FieldDescriptor field, Object value) {
return TextFormat.printer()
if (!this.isSingleLine) {
return TextFormat.debugFormatPrinter().printFieldToString(field, value);
}
return TextFormat.debugFormatPrinter()
.emittingSingleLine(this.isSingleLine)
.enablingSafeDebugFormat(true)
.printFieldToString(field, value);
}

public String toString(UnknownFieldSet fields) {
return TextFormat.printer()
if (!this.isSingleLine) {
return TextFormat.debugFormatPrinter().printToString(fields);
}
return TextFormat.debugFormatPrinter()
.emittingSingleLine(this.isSingleLine)
.enablingSafeDebugFormat(true)
.printToString(fields);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static final class Printer {
private static final Printer DEFAULT_DEBUG_FORMAT =
new Printer(
/* escapeNonAscii= */ true,
/* useShortRepeatedPrimitives= */ true,
/* useShortRepeatedPrimitives= */ false,
TypeRegistry.getEmptyTypeRegistry(),
ExtensionRegistryLite.getEmptyRegistry(),
/* enablingSafeDebugFormat= */ true,
Expand Down

0 comments on commit 1900cbe

Please sign in to comment.