Top Description Inners Fields Constructors Methods
com.google.protobuf

public final Class TextFormat

extends Object
Class Inheritance
Imports
com.google.protobuf.Descriptors.Descriptor, .Descriptors.EnumDescriptor, .Descriptors.EnumValueDescriptor, .Descriptors.FieldDescriptor, java.io.IOException, java.math.BigInteger, java.nio.CharBuffer, java.util.ArrayList, .List, .Locale, .Map, java.util.logging.Logger, java.util.regex.Matcher, .Pattern

Provide text parsing and formatting support for proto2 instances. The implementation largely follows google/protobuf/text_format.cc.
Authors
[email protected] Wenbo Zhu, [email protected] Kenton Varda

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class
TextFormat.ParseException

Thrown when parsing an invalid text format message.

public 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.

public static class
TextFormat.UnknownFieldParseException

Thrown when encountering an unknown field while parsing a text format message.

Field Summary

Modifier and TypeField and Description
private static final Logger
private static final TextFormat.Parser

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static int
digitValue(final byte c)

Interpret a character as a digit (in any base up to 36) and return the numeric value.

public static 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.

public static String
escapeBytes(byte[] input)

Like escapeBytes(ByteString), but used for byte array.

public static String
escapeDoubleQuotesAndBackslashes(final String input)

Escape double quotes and backslashes in a String for unicode output of a message.

pack-priv static String
escapeText(final String input)

Like escapeBytes(ByteString), but escapes a text string.

public static TextFormat.Parser
getParser()

Return a Parser instance which can parse text-format messages.

private static boolean
isHex(final byte c)

Is this a hex digit?

private static boolean
isOctal(final byte c)

Is this an octal digit?

public static void
merge(final Readable input, final Message.Builder builder)

Parse a text-format message from input and merge the contents into builder.

public static void
merge(final CharSequence input, final Message.Builder builder)

Parse a text-format message from input and merge the contents into builder.

public static void
merge(final Readable input, final ExtensionRegistry extensionRegistry, final Message.Builder builder)

Parse a text-format message from input and merge the contents into builder.

public static void
merge(final CharSequence input, final ExtensionRegistry extensionRegistry, final Message.Builder builder)

Parse a text-format message from input and merge the contents into builder.

private static TextFormat.TextGenerator
public static <T extends Message> T

Returns:

the parsed message, guaranteed initialized
parse
(final CharSequence input, final Class<T> protoClass)

Parse a text-format message from input.

public static <T extends Message> T

Returns:

the parsed message, guaranteed initialized
parse
(final CharSequence input, final ExtensionRegistry extensionRegistry, final Class<T> protoClass)

Parse a text-format message from input.

pack-priv static int
parseInt32(final String text)

Parse a 32-bit signed integer from the text.

pack-priv static long
parseInt64(final String text)

Parse a 64-bit signed integer from the text.

private static long
parseInteger(final String text, final boolean isSigned, final boolean isLong)

pack-priv static int
parseUInt32(final String text)

Parse a 32-bit unsigned integer from the text.

pack-priv static long
parseUInt64(final String text)

Parse a 64-bit unsigned integer from the text.

public static void
printField(final Descriptors.FieldDescriptor field, final Object value, final Appendable output)

public static String
public static void
printFieldValue(final Descriptors.FieldDescriptor
the descriptor of the field
field
,
final Object
the value of the field
value
,
final Appendable
the output to which to append the formatted value
output
)

Outputs a textual representation of the value of given field value.

public static String
printToString(final MessageOrBuilder message)

Like print(), but writes directly to a String and returns it.

public static String
printToString(final UnknownFieldSet fields)

Like print(), but writes directly to a String and returns it.

public static String
printToUnicodeString(final MessageOrBuilder message)

Same as printToString(), except that non-ASCII characters in string type fields are not escaped in backslash+octals.

public static String
printToUnicodeString(final UnknownFieldSet fields)

Same as printToString(), except that non-ASCII characters in string type fields are not escaped in backslash+octals.

public static void
printUnicode(final MessageOrBuilder message, final Appendable output)

Same as print(), except that non-ASCII characters are not escaped.

public static void
printUnicode(final UnknownFieldSet fields, final Appendable output)

Same as print(), except that non-ASCII characters are not escaped.

public static void
printUnicodeFieldValue(final Descriptors.FieldDescriptor
the descriptor of the field
field
,
final Object
the value of the field
value
,
final Appendable
the output to which to append the formatted value
output
)

Outputs a unicode textual representation of the value of given field value.

public static void
printUnknownFieldValue(final int
the field's tag number
tag
,
final Object
the value of the field
value
,
final Appendable
the output to which to append the formatted value
output
)

Outputs a textual representation of the value of an unknown field.

private static void
printUnknownFieldValue(final int tag, final Object value, final TextFormat.TextGenerator generator)

public static String
shortDebugString(final MessageOrBuilder message)

Generates a human readable form of this message, useful for debugging and other purposes, with no newline characters.

public static String
shortDebugString(final Descriptors.FieldDescriptor field, final Object value)

Generates a human readable form of the field, useful for debugging and other purposes, with no newline characters.

public static String
shortDebugString(final 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
public static ByteString
unescapeBytes(final CharSequence charString)

Un-escape a byte sequence as escaped using escapeBytes(ByteString).

pack-priv static String
unescapeText(final String input)

Un-escape a text string as escaped using escapeText(String).

public static String
unsignedToString(final int value)

Convert an unsigned 32-bit integer to a string.

public static String
unsignedToString(final long value)

Convert an unsigned 64-bit integer to a string.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait