Package com.google.protobuf
Class TextFormat.Printer
- java.lang.Object
-
- com.google.protobuf.TextFormat.Printer
-
- Enclosing class:
- TextFormat
public static final class TextFormat.Printer extends Object
Helper class for converting protobufs to text.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TextFormat.PrinterescapingNonAscii(boolean escapeNonAscii)Return a new Printer instance with the specified escape mode.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.voidprintField(Descriptors.FieldDescriptor field, Object value, Appendable output)StringprintFieldToString(Descriptors.FieldDescriptor field, Object value)voidprintFieldValue(Descriptors.FieldDescriptor field, Object value, Appendable output)Outputs a textual representation of the value of given field value.StringprintToString(MessageOrBuilder message)Likeprint(), but writes directly to aStringand returns it.StringprintToString(UnknownFieldSet fields)Likeprint(), but writes directly to aStringand returns it.StringshortDebugString(Descriptors.FieldDescriptor field, Object value)Generates a human readable form of the field, useful for debugging and other purposes, with no newline characters.StringshortDebugString(MessageOrBuilder message)Generates a human readable form of this message, useful for debugging and other purposes, with no newline characters.StringshortDebugString(UnknownFieldSet fields)Generates a human readable form of the unknown fields, useful for debugging and other purposes, with no newline characters.TextFormat.PrinterusingTypeRegistry(TypeRegistry typeRegistry)Creates a newTextFormat.Printerusing the given typeRegistry.
-
-
-
Method Detail
-
escapingNonAscii
public TextFormat.Printer escapingNonAscii(boolean escapeNonAscii)
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
public TextFormat.Printer usingTypeRegistry(TypeRegistry typeRegistry)
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
public void print(MessageOrBuilder message, Appendable output) throws IOException
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
public void print(UnknownFieldSet fields, Appendable output) throws IOException
Outputs a textual representation offieldstooutput.- Throws:
IOException
-
printFieldToString
public String printFieldToString(Descriptors.FieldDescriptor field, Object value)
-
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
public String printToString(MessageOrBuilder message)
Likeprint(), but writes directly to aStringand returns it.
-
printToString
public String printToString(UnknownFieldSet fields)
Likeprint(), but writes directly to aStringand returns it.
-
shortDebugString
public String shortDebugString(MessageOrBuilder message)
Generates a human readable form of this message, useful for debugging and other purposes, with no newline characters.
-
shortDebugString
public String 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
public String shortDebugString(UnknownFieldSet fields)
Generates a human readable form of the unknown fields, useful for debugging and other purposes, with no newline characters.
-
-