Show / Hide Table of Contents

Class MessageExtensions

Extension methods on IMessage and IMessage<T>.

Inheritance
System.Object
MessageExtensions
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Google.Protobuf
Assembly: Google.Protobuf.dll
Syntax
public static class MessageExtensions

Methods

IsInitialized(IMessage)

Checks if all required fields in a message have values set. For proto3 messages, this returns true

Declaration
public static bool IsInitialized(this IMessage message)
Parameters
Type Name Description
IMessage message
Returns
Type Description
System.Boolean

MergeDelimitedFrom(IMessage, Stream)

Merges length-delimited data from the given stream into an existing message.

Declaration
public static void MergeDelimitedFrom(this IMessage message, Stream input)
Parameters
Type Name Description
IMessage message

The message to merge the data into.

System.IO.Stream input

Stream containing the data to merge, which must be protobuf-encoded binary data.

Remarks

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

MergeFrom(IMessage, ByteString)

Merges data from the given byte string into an existing message.

Declaration
public static void MergeFrom(this IMessage message, ByteString data)
Parameters
Type Name Description
IMessage message

The message to merge the data into.

ByteString data

The data to merge, which must be protobuf-encoded binary data.

MergeFrom(IMessage, Byte[])

Merges data from the given byte array into an existing message.

Declaration
public static void MergeFrom(this IMessage message, byte[] data)
Parameters
Type Name Description
IMessage message

The message to merge the data into.

System.Byte[] data

The data to merge, which must be protobuf-encoded binary data.

MergeFrom(IMessage, Byte[], Int32, Int32)

Merges data from the given byte array slice into an existing message.

Declaration
public static void MergeFrom(this IMessage message, byte[] data, int offset, int length)
Parameters
Type Name Description
IMessage message

The message to merge the data into.

System.Byte[] data

The data containing the slice to merge, which must be protobuf-encoded binary data.

System.Int32 offset

The offset of the slice to merge.

System.Int32 length

The length of the slice to merge.

MergeFrom(IMessage, Stream)

Merges data from the given stream into an existing message.

Declaration
public static void MergeFrom(this IMessage message, Stream input)
Parameters
Type Name Description
IMessage message

The message to merge the data into.

System.IO.Stream input

Stream containing the data to merge, which must be protobuf-encoded binary data.

ToByteArray(IMessage)

Converts the given message into a byte array in protobuf encoding.

Declaration
public static byte[] ToByteArray(this IMessage message)
Parameters
Type Name Description
IMessage message

The message to convert.

Returns
Type Description
System.Byte[]

The message data as a byte array.

ToByteString(IMessage)

Converts the given message into a byte string in protobuf encoding.

Declaration
public static ByteString ToByteString(this IMessage message)
Parameters
Type Name Description
IMessage message

The message to convert.

Returns
Type Description
ByteString

The message data as a byte string.

WriteDelimitedTo(IMessage, Stream)

Writes the length and then data of the given message to a stream.

Declaration
public static void WriteDelimitedTo(this IMessage message, Stream output)
Parameters
Type Name Description
IMessage message

The message to write.

System.IO.Stream output

The output stream to write to.

WriteTo(IMessage, Stream)

Writes the given message data to the given stream in protobuf encoding.

Declaration
public static void WriteTo(this IMessage message, Stream output)
Parameters
Type Name Description
IMessage message

The message to write to the stream.

System.IO.Stream output

The stream to write to.

Back to top