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 class
Thrown when parsing an invalid text format message.static class
Parser for text-format proto2 instances. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Escape double quotes and backslashes in a String for unicode output of a message.static TextFormat.Parser
Return aTextFormat.Parser
instance which can parse text-format messages.static void
merge
(CharSequence input, ExtensionRegistry extensionRegistry, Message.Builder builder) Parse a text-format message frominput
and merge the contents intobuilder
.static void
merge
(CharSequence input, Message.Builder builder) Parse a text-format message frominput
and merge the contents intobuilder
.static void
merge
(Readable input, ExtensionRegistry extensionRegistry, Message.Builder builder) Parse a text-format message frominput
and merge the contents intobuilder
.static void
merge
(Readable input, Message.Builder builder) Parse a text-format message frominput
and merge the contents intobuilder
.static void
print
(MessageOrBuilder message, Appendable output) Outputs a textual representation of the Protocol Message supplied into the parameter output.static void
print
(UnknownFieldSet fields, Appendable output) Outputs a textual representation offields
tooutput
.static void
printField
(Descriptors.FieldDescriptor field, Object value, Appendable output) static String
printFieldToString
(Descriptors.FieldDescriptor field, Object value) static void
printFieldValue
(Descriptors.FieldDescriptor field, Object value, Appendable output) Outputs a textual representation of the value of given field value.static String
printToString
(MessageOrBuilder message) Likeprint()
, but writes directly to aString
and returns it.static String
printToString
(UnknownFieldSet fields) Likeprint()
, but writes directly to aString
and returns it.static String
printToUnicodeString
(MessageOrBuilder message) Same asprintToString()
, except that non-ASCII characters in string type fields are not escaped in backslash+octals.static String
printToUnicodeString
(UnknownFieldSet fields) Same asprintToString()
, except that non-ASCII characters in string type fields are not escaped in backslash+octals.static void
printUnicode
(MessageOrBuilder message, Appendable output) Same asprint()
, except that non-ASCII characters are not escaped.static void
printUnicode
(UnknownFieldSet fields, Appendable output) Same asprint()
, except that non-ASCII characters are not escaped.static void
printUnknownFieldValue
(int tag, Object value, Appendable output) Outputs a textual representation of the value of an unknown field.static String
shortDebugString
(MessageOrBuilder message) Generates a human readable form of this message, useful for debugging and other purposes, with no newline characters.static String
shortDebugString
(UnknownFieldSet fields) Generates a human readable form of the unknown fields, useful for debugging and other purposes, with no newline characters.static String
unsignedToString
(int value) Convert an unsigned 32-bit integer to a string.static String
unsignedToString
(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 offields
tooutput
.- 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 aString
and returns it. -
printToString
Likeprint()
, but writes directly to aString
and 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.Parser
instance which can parse text-format messages. The returned instance is thread-safe. -
merge
Parse a text-format message frominput
and merge the contents intobuilder
.- Throws:
IOException
-
merge
public static void merge(CharSequence input, Message.Builder builder) throws TextFormat.ParseException Parse a text-format message frominput
and 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 frominput
and 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 frominput
and 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.
-