Package com.google.protobuf
Class TextFormat.Printer
java.lang.Object
com.google.protobuf.TextFormat.Printer
- Enclosing class:
TextFormat
Helper class for converting protobufs to text.
-
Method Summary
Modifier and TypeMethodDescriptionemittingSingleLine
(boolean singleLine) Return a new Printer instance with the specified line formatting status.escapingNonAscii
(boolean escapeNonAscii) Return a new Printer instance with the specified escape mode.void
print
(MessageOrBuilder message, Appendable output) Outputs a textual representation of the Protocol Message supplied into the parameter output.void
print
(UnknownFieldSet fields, Appendable output) Outputs a textual representation offields
tooutput
.void
printField
(Descriptors.FieldDescriptor field, Object value, Appendable output) printFieldToString
(Descriptors.FieldDescriptor field, Object value) void
printFieldValue
(Descriptors.FieldDescriptor field, Object value, Appendable output) Outputs a textual representation of the value of given field value.printToString
(MessageOrBuilder message) Likeprint()
, but writes directly to aString
and returns it.printToString
(UnknownFieldSet fields) Likeprint()
, but writes directly to aString
and returns it.shortDebugString
(Descriptors.FieldDescriptor field, Object value) Deprecated.shortDebugString
(MessageOrBuilder message) Deprecated.Usethis.printer().emittingSingleLine(true).printToString(MessageOrBuilder)
shortDebugString
(UnknownFieldSet fields) Deprecated.Usethis.emittingSingleLine(true).printToString(UnknownFieldSet)
usingExtensionRegistry
(com.google.protobuf.ExtensionRegistryLite extensionRegistry) Creates a newTextFormat.Printer
using the given extensionRegistry.usingTypeRegistry
(TypeRegistry typeRegistry) Creates a newTextFormat.Printer
using the given typeRegistry.
-
Method Details
-
escapingNonAscii
Return a new Printer instance with the specified escape mode.- Parameters:
escapeNonAscii
- If true, the new Printer will escape non-ASCII characters (this is the default behavior. If false, the new Printer will print non-ASCII characters as is. In either case, the new Printer still escapes newlines and quotes in strings.- Returns:
- a new Printer that clones all other configurations from the current
TextFormat.Printer
, with the escape mode set to the given parameter.
-
usingTypeRegistry
Creates a newTextFormat.Printer
using the given typeRegistry. The new Printer clones all other configurations from the currentTextFormat.Printer
.- Throws:
IllegalArgumentException
- if a registry is already set.
-
usingExtensionRegistry
public TextFormat.Printer usingExtensionRegistry(com.google.protobuf.ExtensionRegistryLite extensionRegistry) Creates a newTextFormat.Printer
using the given extensionRegistry. The new Printer clones all other configurations from the currentTextFormat.Printer
.- Throws:
IllegalArgumentException
- if a registry is already set.
-
emittingSingleLine
Return a new Printer instance with the specified line formatting status.- Parameters:
singleLine
- If true, the new Printer will output no newline characters.- Returns:
- a new Printer that clones all other configurations from the current
TextFormat.Printer
, with the singleLine mode set to the given parameter.
-
print
Outputs a textual representation of the Protocol Message supplied into the parameter output. (This representation is the new version of the classic "ProtocolPrinter" output from the original Protocol Buffer system)- Throws:
IOException
-
print
Outputs a textual representation offields
tooutput
.- Throws:
IOException
-
printFieldToString
-
printField
public void printField(Descriptors.FieldDescriptor field, Object value, Appendable output) throws IOException - Throws:
IOException
-
printFieldValue
public void printFieldValue(Descriptors.FieldDescriptor field, Object value, Appendable output) throws IOException Outputs a textual representation of the value of given field value.- Parameters:
field
- the descriptor of the fieldvalue
- the value of the fieldoutput
- the output to which to append the formatted value- Throws:
ClassCastException
- if the value is not appropriate for the given field descriptorIOException
- if there is an exception writing to the output
-
printToString
Likeprint()
, but writes directly to aString
and returns it. -
printToString
Likeprint()
, but writes directly to aString
and returns it. -
shortDebugString
Deprecated.Usethis.printer().emittingSingleLine(true).printToString(MessageOrBuilder)
Generates a human readable form of this message, useful for debugging and other purposes, with no newline characters. -
shortDebugString
@Deprecated @InlineMe(replacement="this.emittingSingleLine(true).printFieldToString(field, value)") public String shortDebugString(Descriptors.FieldDescriptor field, Object value) Deprecated.Usethis.emittingSingleLine(true).printFieldToString(FieldDescriptor, Object)
Generates a human readable form of the field, useful for debugging and other purposes, with no newline characters. -
shortDebugString
@Deprecated @InlineMe(replacement="this.emittingSingleLine(true).printToString(fields)") public String shortDebugString(UnknownFieldSet fields) Deprecated.Usethis.emittingSingleLine(true).printToString(UnknownFieldSet)
Generates a human readable form of the unknown fields, useful for debugging and other purposes, with no newline characters.
-
this.emittingSingleLine(true).printFieldToString(FieldDescriptor, Object)