Class MessageParser (3.27.1) Stay organized with collections Save and categorize content based on your preferences.
public class MessageParserA general message parser, typically used by reflection-based code as all the methodsreturn simpleIMessage.
Inherited Members
Derived Types
Namespace
Google.ProtobufAssembly
Google.Protobuf.dll
Methods
ParseDelimitedFrom(Stream)
public IMessage ParseDelimitedFrom(Stream input)Parses a length-delimited message from the given stream.
| Parameter | |
|---|---|
| Name | Description |
input | StreamThe stream to parse. |
| Returns | |
|---|---|
| Type | Description |
IMessage | The parsed message. |
The stream is expected to contain a length and then the data. Only the amount of dataspecified by the length will be consumed.
ParseFrom(ByteString)
public IMessage ParseFrom(ByteString data)Parses a message from the given byte string.
| Parameter | |
|---|---|
| Name | Description |
data | ByteStringThe data to parse. |
| Returns | |
|---|---|
| Type | Description |
IMessage | The parsed message. |
ParseFrom(CodedInputStream)
public IMessage ParseFrom(CodedInputStream input)Parses a message from the given coded input stream.
| Parameter | |
|---|---|
| Name | Description |
input | CodedInputStreamThe stream to parse. |
| Returns | |
|---|---|
| Type | Description |
IMessage | The parsed message. |
ParseFrom(ReadOnlySequence<byte>)
public IMessage ParseFrom(ReadOnlySequence<byte> data)Parses a message from the given sequence.
| Parameter | |
|---|---|
| Name | Description |
data | ReadOnlySequencebyteThe data to parse. |
| Returns | |
|---|---|
| Type | Description |
IMessage | The parsed message. |
ParseFrom(byte[])
public IMessage ParseFrom(byte[] data)Parses a message from a byte array.
| Parameter | |
|---|---|
| Name | Description |
data | byteThe byte array containing the message. Must not be null. |
| Returns | |
|---|---|
| Type | Description |
IMessage | The newly parsed message. |
ParseFrom(byte[], int, int)
public IMessage ParseFrom(byte[] data, int offset, int length)Parses a message from a byte array slice.
| Parameters | |
|---|---|
| Name | Description |
data | byteThe byte array containing the message. Must not be null. |
offset | intThe offset of the slice to parse. |
length | intThe length of the slice to parse. |
| Returns | |
|---|---|
| Type | Description |
IMessage | The newly parsed message. |
ParseFrom(Stream)
public IMessage ParseFrom(Stream input)Parses a message from the given stream.
| Parameter | |
|---|---|
| Name | Description |
input | StreamThe stream to parse. |
| Returns | |
|---|---|
| Type | Description |
IMessage | The parsed message. |
ParseFrom(ReadOnlySpan<byte>)
public IMessage ParseFrom(ReadOnlySpan<byte> data)Parses a message from the given span.
| Parameter | |
|---|---|
| Name | Description |
data | ReadOnlySpanbyteThe data to parse. |
| Returns | |
|---|---|
| Type | Description |
IMessage | The parsed message. |
ParseJson(string)
public IMessage ParseJson(string json)Parses a message from the given JSON.
| Parameter | |
|---|---|
| Name | Description |
json | stringThe JSON to parse. |
| Returns | |
|---|---|
| Type | Description |
IMessage | The parsed message. |
This method always uses the default JSON parser; it is not affected byWithDiscardUnknownFields(bool). To ignore unknown fields when parsing JSON, create aJsonParser using aJsonParser.Settings withIgnoreUnknownFields set to true and callParse<T>(string) directly.
| Exceptions | |
|---|---|
| Type | Description |
InvalidJsonException | The JSON does not comply with RFC 7159 |
InvalidProtocolBufferException | The JSON does not represent a Protocol Buffers message correctly |
WithDiscardUnknownFields(bool)
public MessageParser WithDiscardUnknownFields(bool discardUnknownFields)Creates a new message parser which optionally discards unknown fields when parsing.
| Parameter | |
|---|---|
| Name | Description |
discardUnknownFields | boolWhether or not to discard unknown fields when parsing. |
| Returns | |
|---|---|
| Type | Description |
MessageParser | A newly configured message parser. |
Note that this does not affect the behavior ofParseJson(string) at all. To ignore unknown fields when parsing JSON, create aJsonParser using aJsonParser.Settings withIgnoreUnknownFields set to true and callParse<T>(string) directly.
WithExtensionRegistry(ExtensionRegistry)
publicMessageParserWithExtensionRegistry(ExtensionRegistryregistry)Creates a new message parser which registers extensions from the specified registry upon creating the message instance
| Parameter | |
|---|---|
| Name | Description |
registry | ExtensionRegistryThe extensions to register |
| Returns | |
|---|---|
| Type | Description |
MessageParser | A newly configured message parser. |
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-10-30 UTC.