Google.Protobuf.MessageParser< T >

A parser for a specific message type.

Summary

This delegates most behavior to the IMessage.MergeFrom implementation within the original type, but provides convenient overloads to parse from a variety of sources.

Most applications will never need to create their own instances of this type; instead, use the static Parser property of a generated message type to obtain a parser for that type.

Details
Template Parameters
T
The type of message to be parsed.

Inheritance

Inherits from: Google.Protobuf.MessageParser

Public functions

MessageParser(Func< T > factory)
Creates a new parser.
ParseDelimitedFrom(Stream input)
new T
Parses a length-delimited message from the given stream.
ParseFrom(byte[] data)
new T
Parses a message from a byte array.
ParseFrom(ByteString data)
new T
Parses a message from the given byte string.
ParseFrom(Stream input)
new T
Parses a message from the given stream.
ParseFrom(CodedInputStream input)
new T
Parses a message from the given coded input stream.
ParseJson(string json)
new T
Parses a message from the given JSON.

Public functions

MessageParser

 MessageParser(
  Func< T > factory
)

Creates a new parser.

The factory method is effectively an optimization over using a generic constraint to require a parameterless constructor: delegates are significantly faster to execute.

Details
Parameters
factory
Function to invoke when a new, empty message is required.

ParseDelimitedFrom

new T ParseDelimitedFrom(
  Stream input
)

Parses a length-delimited message from the given stream.

The stream is expected to contain a length and then the data. Only the amount of data specified by the length will be consumed.

Details
Parameters
input
The stream to parse.
Returns
The parsed message.

ParseFrom

new T ParseFrom(
  byte[] data
)

Parses a message from a byte array.

Details
Parameters
data
The byte array containing the message. Must not be null.
Returns
The newly parsed message.

ParseFrom

new T ParseFrom(
  ByteString data
)

Parses a message from the given byte string.

Details
Parameters
data
The data to parse.
Returns
The parsed message.

ParseFrom

new T ParseFrom(
  Stream input
)

Parses a message from the given stream.

Details
Parameters
input
The stream to parse.
Returns
The parsed message.

ParseFrom

new T ParseFrom(
  CodedInputStream input
)

Parses a message from the given coded input stream.

Details
Parameters
input
The stream to parse.
Returns
The parsed message.

ParseJson

new T ParseJson(
  string json
)

Parses a message from the given JSON.

Details
Parameters
json
The JSON to parse.
Exceptions
InvalidJsonException
The JSON does not comply with RFC 7159
InvalidProtocolBufferException
The JSON does not represent a Protocol Buffers message correctly
Returns
The parsed message.