public final class TextFormat extends 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.
|
static class |
TextFormat.Printer
Helper class for converting protobufs to text.
|
static class |
TextFormat.UnknownFieldParseException
Thrown when encountering an unknown field while parsing a text format message.
|
Modifier and Type | Method and Description |
---|---|
static String |
escapeBytes(byte[] input)
Like
escapeBytes(ByteString) , but used for byte array. |
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.
|
static String |
escapeDoubleQuotesAndBackslashes(String input)
Escape double quotes and backslashes in a String for emittingUnicode output of a message.
|
static TextFormat.Parser |
getParser()
Return a
Parser instance which can parse text-format messages. |
static void |
merge(CharSequence input,
ExtensionRegistry extensionRegistry,
Message.Builder builder)
Parse a text-format message from
input and merge the contents into builder . |
static void |
merge(CharSequence input,
Message.Builder builder)
Parse a text-format message from
input and merge the contents into builder . |
static void |
merge(Readable input,
ExtensionRegistry extensionRegistry,
Message.Builder builder)
Parse a text-format message from
input and merge the contents into builder . |
static void |
merge(Readable input,
Message.Builder builder)
Parse a text-format message from
input and merge the contents into builder . |
static <T extends Message> |
parse(CharSequence input,
Class<T> protoClass)
Parse a text-format message from
input . |
static <T extends Message> |
parse(CharSequence input,
ExtensionRegistry extensionRegistry,
Class<T> protoClass)
Parse a text-format message from
input . |
static void |
print(MessageOrBuilder message,
Appendable output)
Deprecated.
Use
printer().print(MessageOrBuilder, Appendable) |
static void |
print(UnknownFieldSet fields,
Appendable output)
Deprecated.
Use
printer().print(UnknownFieldSet, Appendable) |
static TextFormat.Printer |
printer()
Printer instance which escapes non-ASCII characters.
|
static void |
printField(Descriptors.FieldDescriptor field,
Object value,
Appendable output)
Deprecated.
Use
printer().printField(FieldDescriptor, Object, Appendable) |
static String |
printFieldToString(Descriptors.FieldDescriptor field,
Object value)
Deprecated.
Use
printer().printFieldToString(FieldDescriptor, Object) |
static void |
printFieldValue(Descriptors.FieldDescriptor field,
Object value,
Appendable output)
Deprecated.
Use
printer().printFieldValue(FieldDescriptor, Object, Appendable) |
static String |
printToString(MessageOrBuilder message)
Deprecated.
Use
MessageOrBuilder#toString() |
static String |
printToString(UnknownFieldSet fields)
Deprecated.
|
static String |
printToUnicodeString(MessageOrBuilder message)
Deprecated.
Use
printer().escapingNonAscii(false).printToString(MessageOrBuilder) |
static String |
printToUnicodeString(UnknownFieldSet fields)
Deprecated.
Use
printer().escapingNonAscii(false).printToString(UnknownFieldSet) |
static void |
printUnicode(MessageOrBuilder message,
Appendable output)
Deprecated.
Use
printer().escapingNonAscii(false).print(MessageOrBuilder, Appendable) |
static void |
printUnicode(UnknownFieldSet fields,
Appendable output)
Deprecated.
Use
printer().escapingNonAscii(false).print(UnknownFieldSet, Appendable) |
static void |
printUnicodeFieldValue(Descriptors.FieldDescriptor field,
Object value,
Appendable output)
Deprecated.
Use
printer().escapingNonAscii(false).printFieldValue(FieldDescriptor,
Object, Appendable) |
static void |
printUnknownFieldValue(int tag,
Object value,
Appendable output)
Outputs a textual representation of the value of an unknown field.
|
static String |
shortDebugString(Descriptors.FieldDescriptor field,
Object value)
Deprecated.
Use
printer().shortDebugString(FieldDescriptor, Object) |
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)
Deprecated.
Use
printer().shortDebugString(UnknownFieldSet) |
static ByteString |
unescapeBytes(CharSequence charString)
Un-escape a byte sequence as escaped using
escapeBytes(ByteString) . |
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.
|
@Deprecated public static void print(MessageOrBuilder message, Appendable output) throws IOException
printer().print(MessageOrBuilder, Appendable)
IOException
@Deprecated public static void print(UnknownFieldSet fields, Appendable output) throws IOException
printer().print(UnknownFieldSet, Appendable)
fields
to output
.IOException
@Deprecated public static void printUnicode(MessageOrBuilder message, Appendable output) throws IOException
printer().escapingNonAscii(false).print(MessageOrBuilder, Appendable)
print()
, except that non-ASCII characters are not escaped.IOException
@Deprecated public static void printUnicode(UnknownFieldSet fields, Appendable output) throws IOException
printer().escapingNonAscii(false).print(UnknownFieldSet, Appendable)
print()
, except that non-ASCII characters are not escaped.IOException
public static String shortDebugString(MessageOrBuilder message)
TextFormat.Printer.shortDebugString(MessageOrBuilder)
.@Deprecated public static String shortDebugString(Descriptors.FieldDescriptor field, Object value)
printer().shortDebugString(FieldDescriptor, Object)
@Deprecated public static String shortDebugString(UnknownFieldSet fields)
printer().shortDebugString(UnknownFieldSet)
@Deprecated public static String printToString(MessageOrBuilder message)
MessageOrBuilder#toString()
print()
, but writes directly to a String
and returns it.@Deprecated public static String printToString(UnknownFieldSet fields)
UnknownFieldSet.toString()
print()
, but writes directly to a String
and returns it.@Deprecated public static String printToUnicodeString(MessageOrBuilder message)
printer().escapingNonAscii(false).printToString(MessageOrBuilder)
printToString()
, except that non-ASCII characters in string type fields are not
escaped in backslash+octals.@Deprecated public static String printToUnicodeString(UnknownFieldSet fields)
printer().escapingNonAscii(false).printToString(UnknownFieldSet)
printToString()
, except that non-ASCII characters in string type fields are not
escaped in backslash+octals.@Deprecated public static void printField(Descriptors.FieldDescriptor field, Object value, Appendable output) throws IOException
printer().printField(FieldDescriptor, Object, Appendable)
IOException
@Deprecated public static String printFieldToString(Descriptors.FieldDescriptor field, Object value)
printer().printFieldToString(FieldDescriptor, Object)
@Deprecated public static void printUnicodeFieldValue(Descriptors.FieldDescriptor field, Object value, Appendable output) throws IOException
printer().escapingNonAscii(false).printFieldValue(FieldDescriptor,
Object, Appendable)
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 valueClassCastException
- if the value is not appropriate for the given field descriptorIOException
- if there is an exception writing to the output@Deprecated public static void printFieldValue(Descriptors.FieldDescriptor field, Object value, Appendable output) throws IOException
printer().printFieldValue(FieldDescriptor, Object, Appendable)
field
- the descriptor of the fieldvalue
- the value of the fieldoutput
- the output to which to append the formatted valueClassCastException
- if the value is not appropriate for the given field descriptorIOException
- if there is an exception writing to the outputpublic static void printUnknownFieldValue(int tag, Object value, Appendable output) throws IOException
tag
- the field's tag numbervalue
- the value of the fieldoutput
- the output to which to append the formatted valueClassCastException
- if the value is not appropriate for the given field descriptorIOException
- if there is an exception writing to the outputpublic static TextFormat.Printer printer()
public static String unsignedToString(int value)
public static String unsignedToString(long value)
public static TextFormat.Parser getParser()
Parser
instance which can parse text-format messages. The returned instance is
thread-safe.public static void merge(Readable input, Message.Builder builder) throws IOException
input
and merge the contents into builder
.IOException
public static void merge(CharSequence input, Message.Builder builder) throws TextFormat.ParseException
input
and merge the contents into builder
.TextFormat.ParseException
public static <T extends Message> T parse(CharSequence input, Class<T> protoClass) throws TextFormat.ParseException
input
.TextFormat.ParseException
public static void merge(Readable input, ExtensionRegistry extensionRegistry, Message.Builder builder) throws IOException
input
and merge the contents into builder
.
Extensions will be recognized if they are registered in extensionRegistry
.IOException
public static void merge(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 <T extends Message> T parse(CharSequence input, ExtensionRegistry extensionRegistry, Class<T> protoClass) throws TextFormat.ParseException
input
. Extensions will be recognized if they are
registered in extensionRegistry
.TextFormat.ParseException
public static String escapeBytes(ByteString input)
public static String escapeBytes(byte[] input)
escapeBytes(ByteString)
, but used for byte array.public static ByteString unescapeBytes(CharSequence charString) throws TextFormat.InvalidEscapeSequenceException
escapeBytes(ByteString)
. Two-digit hex
escapes (starting with "\x") are also recognized.Copyright © 2008–2019. All rights reserved.