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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classAn adapter class that can take aMapEntryand returns its key and entry. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final TextFormat.Printerprivate final booleanWhether to escape non ASCII characters with backslash and octal.private final TypeRegistry -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionescapingNonAscii(boolean escapeNonAscii) Return a new Printer instance with the specified escape mode.private voidprint(MessageOrBuilder message, TextFormat.TextGenerator generator) voidprint(MessageOrBuilder message, Appendable output) Outputs a textual representation of the Protocol Message supplied into the parameter output.voidprint(UnknownFieldSet fields, Appendable output) Outputs a textual representation offieldstooutput.private booleanprintAny(MessageOrBuilder message, TextFormat.TextGenerator generator) Attempt to print the 'google.protobuf.Any' message in a human-friendly format.private voidprintField(Descriptors.FieldDescriptor field, Object value, TextFormat.TextGenerator generator) voidprintField(Descriptors.FieldDescriptor field, Object value, Appendable output) printFieldToString(Descriptors.FieldDescriptor field, Object value) private voidprintFieldValue(Descriptors.FieldDescriptor field, Object value, TextFormat.TextGenerator generator) voidprintFieldValue(Descriptors.FieldDescriptor field, Object value, Appendable output) Outputs a textual representation of the value of given field value.private voidprintMessage(MessageOrBuilder message, TextFormat.TextGenerator generator) private voidprintSingleField(Descriptors.FieldDescriptor field, Object value, TextFormat.TextGenerator generator) printToString(MessageOrBuilder message) Likeprint(), but writes directly to aStringand returns it.printToString(UnknownFieldSet fields) Likeprint(), but writes directly to aStringand returns it.private static voidprintUnknownField(int number, int wireType, List<?> values, TextFormat.TextGenerator generator) private static voidprintUnknownFields(UnknownFieldSet unknownFields, TextFormat.TextGenerator generator) private static voidprintUnknownFieldValue(int tag, Object value, TextFormat.TextGenerator generator) shortDebugString(Descriptors.FieldDescriptor field, Object value) Generates a human readable form of the field, useful for debugging and other purposes, with no newline characters.shortDebugString(MessageOrBuilder message) Generates a human readable form of this message, useful for debugging and other purposes, with no newline characters.shortDebugString(UnknownFieldSet fields) Generates a human readable form of the unknown fields, useful for debugging and other purposes, with no newline characters.usingTypeRegistry(TypeRegistry typeRegistry) Creates a newTextFormat.Printerusing the given typeRegistry.
-
Field Details
-
DEFAULT
-
escapeNonAscii
private final boolean escapeNonAsciiWhether to escape non ASCII characters with backslash and octal. -
typeRegistry
-
-
Constructor Details
-
Printer
-
-
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.Printerusing the given typeRegistry. The new Printer clones all other configurations from the currentTextFormat.Printer.- Throws:
IllegalArgumentException- if a registry is already set.
-
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 offieldstooutput.- Throws:
IOException
-
print
- Throws:
IOException
-
printAny
private boolean printAny(MessageOrBuilder message, TextFormat.TextGenerator generator) throws IOException Attempt to print the 'google.protobuf.Any' message in a human-friendly format. Returns false if the message isn't a valid 'google.protobuf.Any' message (in which case the message should be rendered just like a regular message to help debugging).- Throws:
IOException
-
printFieldToString
-
printField
public void printField(Descriptors.FieldDescriptor field, Object value, Appendable output) throws IOException - Throws:
IOException
-
printField
private void printField(Descriptors.FieldDescriptor field, Object value, TextFormat.TextGenerator generator) 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
-
printFieldValue
private void printFieldValue(Descriptors.FieldDescriptor field, Object value, TextFormat.TextGenerator generator) throws IOException - Throws:
IOException
-
printToString
Likeprint(), but writes directly to aStringand returns it. -
printToString
Likeprint(), but writes directly to aStringand returns it. -
shortDebugString
Generates a human readable form of this message, useful for debugging and other purposes, with no newline characters. -
shortDebugString
Generates a human readable form of the field, useful for debugging and other purposes, with no newline characters. -
shortDebugString
Generates a human readable form of the unknown fields, useful for debugging and other purposes, with no newline characters. -
printUnknownFieldValue
private static void printUnknownFieldValue(int tag, Object value, TextFormat.TextGenerator generator) throws IOException - Throws:
IOException
-
printMessage
private void printMessage(MessageOrBuilder message, TextFormat.TextGenerator generator) throws IOException - Throws:
IOException
-
printSingleField
private void printSingleField(Descriptors.FieldDescriptor field, Object value, TextFormat.TextGenerator generator) throws IOException - Throws:
IOException
-
printUnknownFields
private static void printUnknownFields(UnknownFieldSet unknownFields, TextFormat.TextGenerator generator) throws IOException - Throws:
IOException
-
printUnknownField
private static void printUnknownField(int number, int wireType, List<?> values, TextFormat.TextGenerator generator) throws IOException - Throws:
IOException
-