Package com.google.protobuf
Class TextFormat.Parser
java.lang.Object
com.google.protobuf.TextFormat.Parser
- Enclosing class:
TextFormat
Parser for text-format proto2 instances. This class is thread-safe. The implementation largely
follows google/protobuf/text_format.cc.
Use TextFormat.getParser()
to obtain the default parser, or TextFormat.Parser.Builder
to
control the parser behavior.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Builder that can be used to obtain new instances ofTextFormat.Parser
.static enum
Determines if repeated values for non-repeated fields and oneofs are permitted.(package private) static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
private final boolean
private final boolean
private static final int
private TextFormatParseInfoTree.Builder
private final int
private final TextFormat.Parser.SingularOverwritePolicy
private final TypeRegistry
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Parser
(TypeRegistry typeRegistry, boolean allowUnknownFields, boolean allowUnknownEnumValues, boolean allowUnknownExtensions, TextFormat.Parser.SingularOverwritePolicy singularOverwritePolicy, TextFormatParseInfoTree.Builder parseInfoTreeBuilder, int recursionLimit) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
checkUnknownFields
(List<TextFormat.Parser.UnknownField> unknownFields) private void
consumeFieldValue
(TextFormat.Tokenizer tokenizer, ExtensionRegistry extensionRegistry, MessageReflection.MergeTarget target, Descriptors.FieldDescriptor field, ExtensionRegistry.ExtensionInfo extension, TextFormatParseInfoTree.Builder parseTreeBuilder, List<TextFormat.Parser.UnknownField> unknownFields, int recursionLimit) Parse a single field value fromtokenizer
and merge it intobuilder
.private void
consumeFieldValues
(TextFormat.Tokenizer tokenizer, ExtensionRegistry extensionRegistry, MessageReflection.MergeTarget target, Descriptors.FieldDescriptor field, ExtensionRegistry.ExtensionInfo extension, TextFormatParseInfoTree.Builder parseTreeBuilder, List<TextFormat.Parser.UnknownField> unknownFields, int recursionLimit) Parse a one or more field values fromtokenizer
and merge it intobuilder
.private void
consumeFullTypeName
(TextFormat.Tokenizer tokenizer) private void
guessFieldTypeAndSkip
(TextFormat.Tokenizer tokenizer, Descriptors.Descriptor type, int recursionLimit) Tries to guess the type of this field and skip it.void
merge
(CharSequence input, ExtensionRegistry extensionRegistry, Message.Builder builder) Parse a text-format message frominput
and merge the contents intobuilder
.void
merge
(CharSequence input, Message.Builder builder) Parse a text-format message frominput
and merge the contents intobuilder
.void
merge
(Readable input, ExtensionRegistry extensionRegistry, Message.Builder builder) Parse a text-format message frominput
and merge the contents intobuilder
.void
merge
(Readable input, Message.Builder builder) Parse a text-format message frominput
and merge the contents intobuilder
.private void
mergeAnyFieldValue
(TextFormat.Tokenizer tokenizer, ExtensionRegistry extensionRegistry, MessageReflection.MergeTarget target, TextFormatParseInfoTree.Builder parseTreeBuilder, List<TextFormat.Parser.UnknownField> unknownFields, Descriptors.Descriptor anyDescriptor, int recursionLimit) private void
mergeField
(TextFormat.Tokenizer tokenizer, ExtensionRegistry extensionRegistry, MessageReflection.MergeTarget target, TextFormatParseInfoTree.Builder parseTreeBuilder, List<TextFormat.Parser.UnknownField> unknownFields, int recursionLimit) Parse a single field fromtokenizer
and merge it intotarget
.private void
mergeField
(TextFormat.Tokenizer tokenizer, ExtensionRegistry extensionRegistry, MessageReflection.MergeTarget target, List<TextFormat.Parser.UnknownField> unknownFields, int recursionLimit) Parse a single field fromtokenizer
and merge it intobuilder
.static TextFormat.Parser.Builder
Returns a new instance ofTextFormat.Parser.Builder
.private void
skipField
(TextFormat.Tokenizer tokenizer, Descriptors.Descriptor type, int recursionLimit) Skips the next field including the field's name and value.private void
skipFieldMessage
(TextFormat.Tokenizer tokenizer, Descriptors.Descriptor type, int recursionLimit) Skips the whole body of a message including the beginning delimiter and the ending delimiter.private void
skipFieldShortFormedRepeated
(TextFormat.Tokenizer tokenizer, boolean scalarAllowed, Descriptors.Descriptor type, int recursionLimit) Skips a short-formed repeated field value.private void
skipFieldValue
(TextFormat.Tokenizer tokenizer) Skips a field value.private static StringBuilder
toStringBuilder
(Readable input)
-
Field Details
-
typeRegistry
-
allowUnknownFields
private final boolean allowUnknownFields -
allowUnknownEnumValues
private final boolean allowUnknownEnumValues -
allowUnknownExtensions
private final boolean allowUnknownExtensions -
singularOverwritePolicy
-
parseInfoTreeBuilder
-
recursionLimit
private final int recursionLimit -
BUFFER_SIZE
private static final int BUFFER_SIZE- See Also:
-
-
Constructor Details
-
Parser
private Parser(TypeRegistry typeRegistry, boolean allowUnknownFields, boolean allowUnknownEnumValues, boolean allowUnknownExtensions, TextFormat.Parser.SingularOverwritePolicy singularOverwritePolicy, TextFormatParseInfoTree.Builder parseInfoTreeBuilder, int recursionLimit)
-
-
Method Details
-
newBuilder
Returns a new instance ofTextFormat.Parser.Builder
. -
merge
Parse a text-format message frominput
and merge the contents intobuilder
.- Throws:
IOException
-
merge
Parse a text-format message frominput
and merge the contents intobuilder
.- Throws:
TextFormat.ParseException
-
merge
public 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
-
toStringBuilder
- Throws:
IOException
-
checkUnknownFields
private void checkUnknownFields(List<TextFormat.Parser.UnknownField> unknownFields) throws TextFormat.ParseException - Throws:
TextFormat.ParseException
-
merge
public 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
-
mergeField
private void mergeField(TextFormat.Tokenizer tokenizer, ExtensionRegistry extensionRegistry, MessageReflection.MergeTarget target, List<TextFormat.Parser.UnknownField> unknownFields, int recursionLimit) throws TextFormat.ParseException Parse a single field fromtokenizer
and merge it intobuilder
.- Throws:
TextFormat.ParseException
-
mergeField
private void mergeField(TextFormat.Tokenizer tokenizer, ExtensionRegistry extensionRegistry, MessageReflection.MergeTarget target, TextFormatParseInfoTree.Builder parseTreeBuilder, List<TextFormat.Parser.UnknownField> unknownFields, int recursionLimit) throws TextFormat.ParseException Parse a single field fromtokenizer
and merge it intotarget
.- Throws:
TextFormat.ParseException
-
consumeFullTypeName
- Throws:
TextFormat.ParseException
-
consumeFieldValues
private void consumeFieldValues(TextFormat.Tokenizer tokenizer, ExtensionRegistry extensionRegistry, MessageReflection.MergeTarget target, Descriptors.FieldDescriptor field, ExtensionRegistry.ExtensionInfo extension, TextFormatParseInfoTree.Builder parseTreeBuilder, List<TextFormat.Parser.UnknownField> unknownFields, int recursionLimit) throws TextFormat.ParseException Parse a one or more field values fromtokenizer
and merge it intobuilder
.- Throws:
TextFormat.ParseException
-
consumeFieldValue
private void consumeFieldValue(TextFormat.Tokenizer tokenizer, ExtensionRegistry extensionRegistry, MessageReflection.MergeTarget target, Descriptors.FieldDescriptor field, ExtensionRegistry.ExtensionInfo extension, TextFormatParseInfoTree.Builder parseTreeBuilder, List<TextFormat.Parser.UnknownField> unknownFields, int recursionLimit) throws TextFormat.ParseException Parse a single field value fromtokenizer
and merge it intobuilder
.- Throws:
TextFormat.ParseException
-
mergeAnyFieldValue
private void mergeAnyFieldValue(TextFormat.Tokenizer tokenizer, ExtensionRegistry extensionRegistry, MessageReflection.MergeTarget target, TextFormatParseInfoTree.Builder parseTreeBuilder, List<TextFormat.Parser.UnknownField> unknownFields, Descriptors.Descriptor anyDescriptor, int recursionLimit) throws TextFormat.ParseException - Throws:
TextFormat.ParseException
-
skipField
private void skipField(TextFormat.Tokenizer tokenizer, Descriptors.Descriptor type, int recursionLimit) throws TextFormat.ParseException Skips the next field including the field's name and value.- Throws:
TextFormat.ParseException
-
skipFieldMessage
private void skipFieldMessage(TextFormat.Tokenizer tokenizer, Descriptors.Descriptor type, int recursionLimit) throws TextFormat.ParseException Skips the whole body of a message including the beginning delimiter and the ending delimiter.- Throws:
TextFormat.ParseException
-
skipFieldValue
Skips a field value.- Throws:
TextFormat.ParseException
-
guessFieldTypeAndSkip
private void guessFieldTypeAndSkip(TextFormat.Tokenizer tokenizer, Descriptors.Descriptor type, int recursionLimit) throws TextFormat.ParseException Tries to guess the type of this field and skip it.If this field is not a message, there should be a ":" between the field name and the field value and also the field value should not start with "{" or "invalid input: '<'" which indicates the beginning of a message body. If there is no ":" or there is a "{" or "invalid input: '<'" after ":", this field has to be a message or the input is ill-formed. For short-formed repeated fields (i.e. with "[]"), if it is repeated scalar, there must be a ":" between the field name and the starting "[" .
- Throws:
TextFormat.ParseException
-
skipFieldShortFormedRepeated
private void skipFieldShortFormedRepeated(TextFormat.Tokenizer tokenizer, boolean scalarAllowed, Descriptors.Descriptor type, int recursionLimit) throws TextFormat.ParseException Skips a short-formed repeated field value.Reports an error if scalar type is not allowed but showing up inside "[]".
- Throws:
TextFormat.ParseException
-