Package com.google.protobuf
Class TextFormat
java.lang.Object
com.google.protobuf.TextFormat
Provide text parsing and formatting support for proto2 instances.
The implementation largely follows google/protobuf/text_format.cc.
- Author:
- wenboz@google.com Wenbo Zhu, kenton@google.com Kenton Varda
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThrown when parsing an invalid text format message.static classParser for text-format proto2 instances. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringEscape double quotes and backslashes in a String for unicode output of a message.static TextFormat.ParserReturn aTextFormat.Parserinstance which can parse text-format messages.static voidmerge(CharSequence input, ExtensionRegistry extensionRegistry, Message.Builder builder) Parse a text-format message frominputand merge the contents intobuilder.static voidmerge(CharSequence input, Message.Builder builder) Parse a text-format message frominputand merge the contents intobuilder.static voidmerge(Readable input, ExtensionRegistry extensionRegistry, Message.Builder builder) Parse a text-format message frominputand merge the contents intobuilder.static voidmerge(Readable input, Message.Builder builder) Parse a text-format message frominputand merge the contents intobuilder.static voidprint(MessageOrBuilder message, Appendable output) Outputs a textual representation of the Protocol Message supplied into the parameter output.static voidprint(UnknownFieldSet fields, Appendable output) Outputs a textual representation offieldstooutput.static voidprintField(Descriptors.FieldDescriptor field, Object value, Appendable output) static StringprintFieldToString(Descriptors.FieldDescriptor field, Object value) static voidprintFieldValue(Descriptors.FieldDescriptor field, Object value, Appendable output) Outputs a textual representation of the value of given field value.static StringprintToString(MessageOrBuilder message) Likeprint(), but writes directly to aStringand returns it.static StringprintToString(UnknownFieldSet fields) Likeprint(), but writes directly to aStringand returns it.static StringprintToUnicodeString(MessageOrBuilder message) Same asprintToString(), except that non-ASCII characters in string type fields are not escaped in backslash+octals.static StringprintToUnicodeString(UnknownFieldSet fields) Same asprintToString(), except that non-ASCII characters in string type fields are not escaped in backslash+octals.static voidprintUnicode(MessageOrBuilder message, Appendable output) Same asprint(), except that non-ASCII characters are not escaped.static voidprintUnicode(UnknownFieldSet fields, Appendable output) Same asprint(), except that non-ASCII characters are not escaped.static voidprintUnknownFieldValue(int tag, Object value, Appendable output) Outputs a textual representation of the value of an unknown field.static StringshortDebugString(MessageOrBuilder message) Generates a human readable form of this message, useful for debugging and other purposes, with no newline characters.static StringshortDebugString(UnknownFieldSet fields) Generates a human readable form of the unknown fields, useful for debugging and other purposes, with no newline characters.static StringunsignedToString(int value) Convert an unsigned 32-bit integer to a string.static StringunsignedToString(long value) Convert an unsigned 64-bit integer to a string.
-
Method Details
-
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
-
printUnicode
Same asprint(), except that non-ASCII characters are not escaped.- Throws:
IOException
-
printUnicode
Same asprint(), except that non-ASCII characters are not escaped.- Throws:
IOException
-
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 unknown fields, useful for debugging and other purposes, with no newline characters. -
printToString
Likeprint(), but writes directly to aStringand returns it. -
printToString
Likeprint(), but writes directly to aStringand returns it. -
printToUnicodeString
Same asprintToString(), except that non-ASCII characters in string type fields are not escaped in backslash+octals. -
printToUnicodeString
Same asprintToString(), except that non-ASCII characters in string type fields are not escaped in backslash+octals. -
printField
public static void printField(Descriptors.FieldDescriptor field, Object value, Appendable output) throws IOException - Throws:
IOException
-
printFieldToString
-
printFieldValue
public static 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
-
printUnknownFieldValue
public static void printUnknownFieldValue(int tag, Object value, Appendable output) throws IOException Outputs a textual representation of the value of an unknown field.- Parameters:
tag- the field's tag numbervalue- 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
-
unsignedToString
Convert an unsigned 32-bit integer to a string. -
unsignedToString
Convert an unsigned 64-bit integer to a string. -
getParser
Return aTextFormat.Parserinstance which can parse text-format messages. The returned instance is thread-safe. -
merge
Parse a text-format message frominputand merge the contents intobuilder.- Throws:
IOException
-
merge
public static void merge(CharSequence input, Message.Builder builder) throws TextFormat.ParseException Parse a text-format message frominputand merge the contents intobuilder.- Throws:
TextFormat.ParseException
-
merge
public static void merge(Readable input, ExtensionRegistry extensionRegistry, Message.Builder builder) throws IOException Parse a text-format message frominputand merge the contents intobuilder. Extensions will be recognized if they are registered inextensionRegistry.- Throws:
IOException
-
merge
public static void merge(CharSequence input, ExtensionRegistry extensionRegistry, Message.Builder builder) throws TextFormat.ParseException Parse a text-format message frominputand merge the contents intobuilder. Extensions will be recognized if they are registered inextensionRegistry.- Throws:
TextFormat.ParseException
-
escapeDoubleQuotesAndBackslashes
Escape double quotes and backslashes in a String for unicode output of a message.
-