public final class TextFormat
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
TextFormat.InvalidEscapeSequenceException
Thrown by
unescapeBytes(java.lang.CharSequence) and
unescapeText(java.lang.String) when an invalid escape sequence is seen. |
static class |
TextFormat.ParseException
Thrown when parsing an invalid text format message.
|
static class |
TextFormat.Parser
Parser for text-format proto2 instances.
|
private static class |
TextFormat.Printer
Helper class for converting protobufs to text.
|
private static class |
TextFormat.TextGenerator
An inner class for writing text to the output stream.
|
private static class |
TextFormat.Tokenizer
Represents a stream of tokens parsed from a
String . |
static class |
TextFormat.UnknownFieldParseException
Thrown when encountering an unknown field while parsing
a text format message.
|
Modifier and Type | Field and Description |
---|---|
private static java.util.logging.Logger |
logger |
private static TextFormat.Parser |
PARSER |
Modifier | Constructor and Description |
---|---|
private |
TextFormat() |
Modifier and Type | Method and Description |
---|---|
private static int |
digitValue(byte c)
Interpret a character as a digit (in any base up to 36) and return the
numeric value.
|
static java.lang.String |
escapeBytes(byte[] input)
Like
escapeBytes(ByteString) , but used for byte array. |
static java.lang.String |
escapeBytes(ByteString input)
Escapes bytes in the format used in protocol buffer text format, which
is the same as the format used for C string literals.
|
static java.lang.String |
escapeDoubleQuotesAndBackslashes(java.lang.String input)
Escape double quotes and backslashes in a String for unicode output of a message.
|
(package private) static java.lang.String |
escapeText(java.lang.String input)
Like
escapeBytes(ByteString) , but escapes a text string. |
static TextFormat.Parser |
getParser()
Return a
Parser instance which can parse text-format
messages. |
private static boolean |
isHex(byte c)
Is this a hex digit?
|
private static boolean |
isOctal(byte c)
Is this an octal digit?
|
static void |
merge(java.lang.CharSequence input,
ExtensionRegistry extensionRegistry,
Message.Builder builder)
Parse a text-format message from
input and merge the contents
into builder . |
static void |
merge(java.lang.CharSequence input,
Message.Builder builder)
Parse a text-format message from
input and merge the contents
into builder . |
static void |
merge(java.lang.Readable input,
ExtensionRegistry extensionRegistry,
Message.Builder builder)
Parse a text-format message from
input and merge the contents
into builder . |
static void |
merge(java.lang.Readable input,
Message.Builder builder)
Parse a text-format message from
input and merge the contents
into builder . |
private static TextFormat.TextGenerator |
multiLineOutput(java.lang.Appendable output) |
(package private) static int |
parseInt32(java.lang.String text)
Parse a 32-bit signed integer from the text.
|
(package private) static long |
parseInt64(java.lang.String text)
Parse a 64-bit signed integer from the text.
|
private static long |
parseInteger(java.lang.String text,
boolean isSigned,
boolean isLong) |
(package private) static int |
parseUInt32(java.lang.String text)
Parse a 32-bit unsigned integer from the text.
|
(package private) static long |
parseUInt64(java.lang.String text)
Parse a 64-bit unsigned integer from the text.
|
static void |
print(MessageOrBuilder message,
java.lang.Appendable output)
Outputs a textual representation of the Protocol Message supplied into
the parameter output.
|
static void |
print(UnknownFieldSet fields,
java.lang.Appendable output)
Outputs a textual representation of
fields to output . |
static void |
printField(Descriptors.FieldDescriptor field,
java.lang.Object value,
java.lang.Appendable output) |
static java.lang.String |
printFieldToString(Descriptors.FieldDescriptor field,
java.lang.Object value) |
static void |
printFieldValue(Descriptors.FieldDescriptor field,
java.lang.Object value,
java.lang.Appendable output)
Outputs a textual representation of the value of given field value.
|
static java.lang.String |
printToString(MessageOrBuilder message)
Like
print() , but writes directly to a String and
returns it. |
static java.lang.String |
printToString(UnknownFieldSet fields)
Like
print() , but writes directly to a String and
returns it. |
static java.lang.String |
printToUnicodeString(MessageOrBuilder message)
Same as
printToString() , except that non-ASCII characters
in string type fields are not escaped in backslash+octals. |
static java.lang.String |
printToUnicodeString(UnknownFieldSet fields)
Same as
printToString() , except that non-ASCII characters
in string type fields are not escaped in backslash+octals. |
static void |
printUnicode(MessageOrBuilder message,
java.lang.Appendable output)
Same as
print() , except that non-ASCII characters are not
escaped. |
static void |
printUnicode(UnknownFieldSet fields,
java.lang.Appendable output)
Same as
print() , except that non-ASCII characters are not
escaped. |
static void |
printUnicodeFieldValue(Descriptors.FieldDescriptor field,
java.lang.Object value,
java.lang.Appendable output)
Outputs a unicode textual representation of the value of given field value.
|
static void |
printUnknownFieldValue(int tag,
java.lang.Object value,
java.lang.Appendable output)
Outputs a textual representation of the value of an unknown field.
|
private static void |
printUnknownFieldValue(int tag,
java.lang.Object value,
TextFormat.TextGenerator generator) |
static java.lang.String |
shortDebugString(Descriptors.FieldDescriptor field,
java.lang.Object value)
Generates a human readable form of the field, useful for debugging
and other purposes, with no newline characters.
|
static java.lang.String |
shortDebugString(MessageOrBuilder message)
Generates a human readable form of this message, useful for debugging and
other purposes, with no newline characters.
|
static java.lang.String |
shortDebugString(UnknownFieldSet fields)
Generates a human readable form of the unknown fields, useful for debugging
and other purposes, with no newline characters.
|
private static TextFormat.TextGenerator |
singleLineOutput(java.lang.Appendable output) |
static ByteString |
unescapeBytes(java.lang.CharSequence charString)
Un-escape a byte sequence as escaped using
escapeBytes(ByteString) . |
(package private) static java.lang.String |
unescapeText(java.lang.String input)
Un-escape a text string as escaped using
escapeText(String) . |
static java.lang.String |
unsignedToString(int value)
Convert an unsigned 32-bit integer to a string.
|
static java.lang.String |
unsignedToString(long value)
Convert an unsigned 64-bit integer to a string.
|
private static final java.util.logging.Logger logger
private static final TextFormat.Parser PARSER
public static void print(MessageOrBuilder message, java.lang.Appendable output) throws java.io.IOException
java.io.IOException
public static void print(UnknownFieldSet fields, java.lang.Appendable output) throws java.io.IOException
fields
to output
.java.io.IOException
public static void printUnicode(MessageOrBuilder message, java.lang.Appendable output) throws java.io.IOException
print()
, except that non-ASCII characters are not
escaped.java.io.IOException
public static void printUnicode(UnknownFieldSet fields, java.lang.Appendable output) throws java.io.IOException
print()
, except that non-ASCII characters are not
escaped.java.io.IOException
public static java.lang.String shortDebugString(MessageOrBuilder message)
public static java.lang.String shortDebugString(Descriptors.FieldDescriptor field, java.lang.Object value)
public static java.lang.String shortDebugString(UnknownFieldSet fields)
public static java.lang.String printToString(MessageOrBuilder message)
print()
, but writes directly to a String
and
returns it.public static java.lang.String printToString(UnknownFieldSet fields)
print()
, but writes directly to a String
and
returns it.public static java.lang.String printToUnicodeString(MessageOrBuilder message)
printToString()
, except that non-ASCII characters
in string type fields are not escaped in backslash+octals.public static java.lang.String printToUnicodeString(UnknownFieldSet fields)
printToString()
, except that non-ASCII characters
in string type fields are not escaped in backslash+octals.public static void printField(Descriptors.FieldDescriptor field, java.lang.Object value, java.lang.Appendable output) throws java.io.IOException
java.io.IOException
public static java.lang.String printFieldToString(Descriptors.FieldDescriptor field, java.lang.Object value)
public static void printUnicodeFieldValue(Descriptors.FieldDescriptor field, java.lang.Object value, java.lang.Appendable output) throws java.io.IOException
Same as printFieldValue()
, except that non-ASCII characters in string type fields
are not escaped in backslash+octals.
field
- the descriptor of the fieldvalue
- the value of the fieldoutput
- the output to which to append the formatted valuejava.lang.ClassCastException
- if the value is not appropriate for the given field descriptorjava.io.IOException
- if there is an exception writing to the outputpublic static void printFieldValue(Descriptors.FieldDescriptor field, java.lang.Object value, java.lang.Appendable output) throws java.io.IOException
field
- the descriptor of the fieldvalue
- the value of the fieldoutput
- the output to which to append the formatted valuejava.lang.ClassCastException
- if the value is not appropriate for the
given field descriptorjava.io.IOException
- if there is an exception writing to the outputpublic static void printUnknownFieldValue(int tag, java.lang.Object value, java.lang.Appendable output) throws java.io.IOException
tag
- the field's tag numbervalue
- the value of the fieldoutput
- the output to which to append the formatted valuejava.lang.ClassCastException
- if the value is not appropriate for the
given field descriptorjava.io.IOException
- if there is an exception writing to the outputprivate static void printUnknownFieldValue(int tag, java.lang.Object value, TextFormat.TextGenerator generator) throws java.io.IOException
java.io.IOException
public static java.lang.String unsignedToString(int value)
public static java.lang.String unsignedToString(long value)
private static TextFormat.TextGenerator multiLineOutput(java.lang.Appendable output)
private static TextFormat.TextGenerator singleLineOutput(java.lang.Appendable output)
public static TextFormat.Parser getParser()
Parser
instance which can parse text-format
messages. The returned instance is thread-safe.public static void merge(java.lang.Readable input, Message.Builder builder) throws java.io.IOException
input
and merge the contents
into builder
.java.io.IOException
public static void merge(java.lang.CharSequence input, Message.Builder builder) throws TextFormat.ParseException
input
and merge the contents
into builder
.TextFormat.ParseException
public static void merge(java.lang.Readable input, ExtensionRegistry extensionRegistry, Message.Builder builder) throws java.io.IOException
input
and merge the contents
into builder
. Extensions will be recognized if they are
registered in extensionRegistry
.java.io.IOException
public static void merge(java.lang.CharSequence input, ExtensionRegistry extensionRegistry, Message.Builder builder) throws TextFormat.ParseException
input
and merge the contents
into builder
. Extensions will be recognized if they are
registered in extensionRegistry
.TextFormat.ParseException
public static java.lang.String escapeBytes(ByteString input)
public static java.lang.String escapeBytes(byte[] input)
escapeBytes(ByteString)
, but used for byte array.public static ByteString unescapeBytes(java.lang.CharSequence charString) throws TextFormat.InvalidEscapeSequenceException
escapeBytes(ByteString)
. Two-digit hex escapes (starting with
"\x") are also recognized.static java.lang.String escapeText(java.lang.String input)
escapeBytes(ByteString)
, but escapes a text string.
Non-ASCII characters are first encoded as UTF-8, then each byte is escaped
individually as a 3-digit octal escape. Yes, it's weird.public static java.lang.String escapeDoubleQuotesAndBackslashes(java.lang.String input)
static java.lang.String unescapeText(java.lang.String input) throws TextFormat.InvalidEscapeSequenceException
escapeText(String)
.
Two-digit hex escapes (starting with "\x") are also recognized.private static boolean isOctal(byte c)
private static boolean isHex(byte c)
private static int digitValue(byte c)
Character.digit()
but we don't accept
non-ASCII digits.static int parseInt32(java.lang.String text) throws java.lang.NumberFormatException
Integer.parseInt()
, this function recognizes the prefixes "0x"
and "0" to signify hexadecimal and octal numbers, respectively.java.lang.NumberFormatException
static int parseUInt32(java.lang.String text) throws java.lang.NumberFormatException
Integer.parseInt()
, this function recognizes the prefixes "0x"
and "0" to signify hexadecimal and octal numbers, respectively. The
result is coerced to a (signed) int
when returned since Java has
no unsigned integer type.java.lang.NumberFormatException
static long parseInt64(java.lang.String text) throws java.lang.NumberFormatException
Integer.parseInt()
, this function recognizes the prefixes "0x"
and "0" to signify hexadecimal and octal numbers, respectively.java.lang.NumberFormatException
static long parseUInt64(java.lang.String text) throws java.lang.NumberFormatException
Integer.parseInt()
, this function recognizes the prefixes "0x"
and "0" to signify hexadecimal and octal numbers, respectively. The
result is coerced to a (signed) long
when returned since Java has
no unsigned long type.java.lang.NumberFormatException
private static long parseInteger(java.lang.String text, boolean isSigned, boolean isLong) throws java.lang.NumberFormatException
java.lang.NumberFormatException