Skip to content

Commit 5777d3b

Browse files
Restore the long-deprecated static functions on TextFormat.
These functions were intended to be temporary shims and have been deprecated since 2019. However, to minimize difficulty for customers to upgrade to 4.x when they are using stale libraries, these are being readded. PiperOrigin-RevId: 780690886
1 parent 9c0068d commit 5777d3b

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

java/core/src/main/java/com/google/protobuf/TextFormat.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,77 @@ private static void printUnknownField(
908908
}
909909
}
910910

911+
/**
912+
* Outputs a textual representation of the Protocol Message supplied into the parameter output.
913+
* (This representation is the new version of the classic "ProtocolPrinter" output from the
914+
* original Protocol Buffer system)
915+
*
916+
* @deprecated Use {@code printer().print(MessageOrBuilder, Appendable)}
917+
*/
918+
@Deprecated
919+
@InlineMe(
920+
replacement = "TextFormat.printer().print(message, output)",
921+
imports = "com.google.protobuf.TextFormat")
922+
public static void print(final MessageOrBuilder message, final Appendable output)
923+
throws IOException {
924+
printer().print(message, output);
925+
}
926+
927+
/**
928+
* Same as {@code print()}, except that non-ASCII characters are not escaped.
929+
*
930+
* @deprecated Use {@code printer().escapingNonAscii(false).print(MessageOrBuilder, Appendable)}
931+
*/
932+
@Deprecated
933+
public static void printUnicode(final MessageOrBuilder message, final Appendable output)
934+
throws IOException {
935+
printer()
936+
.escapingNonAscii(false)
937+
.print(message, output, Printer.FieldReporterLevel.PRINT_UNICODE);
938+
}
939+
940+
/**
941+
* Like {@code print()}, but writes directly to a {@code String} and returns it.
942+
*
943+
* @deprecated Use {@code message.toString()}
944+
*/
945+
@Deprecated
946+
public static String printToString(final MessageOrBuilder message) {
947+
return printer().printToString(message, Printer.FieldReporterLevel.TEXTFORMAT_PRINT_TO_STRING);
948+
}
949+
950+
/**
951+
* Same as {@code printToString()}, except that non-ASCII characters in string type fields are not
952+
* escaped in backslash+octals.
953+
*
954+
* @deprecated Use {@code printer().escapingNonAscii(false).printToString(MessageOrBuilder)}
955+
*/
956+
@Deprecated
957+
public static String printToUnicodeString(final MessageOrBuilder message) {
958+
return printer()
959+
.escapingNonAscii(false)
960+
.printToString(message, Printer.FieldReporterLevel.PRINT_UNICODE);
961+
}
962+
963+
/**
964+
* Outputs a textual representation of the value of given field value.
965+
*
966+
* @deprecated Use {@code printer().printFieldValue(FieldDescriptor, Object, Appendable)}
967+
* @param field the descriptor of the field
968+
* @param value the value of the field
969+
* @param output the output to which to append the formatted value
970+
* @throws ClassCastException if the value is not appropriate for the given field descriptor
971+
* @throws IOException if there is an exception writing to the output
972+
*/
973+
@Deprecated
974+
@InlineMe(
975+
replacement = "TextFormat.printer().printFieldValue(field, value, output)",
976+
imports = "com.google.protobuf.TextFormat")
977+
public static void printFieldValue(
978+
final FieldDescriptor field, final Object value, final Appendable output) throws IOException {
979+
printer().printFieldValue(field, value, output);
980+
}
981+
911982
/** Convert an unsigned 32-bit integer to a string. */
912983
public static String unsignedToString(final int value) {
913984
if (value >= 0) {

0 commit comments

Comments
 (0)