public static class MessageExtensionsExtension methods on IMessage and IMessage<T>.
Namespace
Google.ProtobufAssembly
Google.Protobuf.dll
Methods
IsInitialized(IMessage)
public static bool IsInitialized(this IMessage message)Checks if all required fields in a message have values set. For proto3 messages, this returns true.
| Parameter | |
|---|---|
| Name | Description |
message |
IMessage |
| Returns | |
|---|---|
| Type | Description |
bool |
|
MergeDelimitedFrom(IMessage, Stream)
public static void MergeDelimitedFrom(this IMessage message, Stream input)Merges length-delimited data from the given stream into an existing message.
| Parameters | |
|---|---|
| Name | Description |
message |
IMessageThe message to merge the data into. |
input |
StreamStream containing the data to merge, which must be protobuf-encoded binary data. |
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)
public static void MergeFrom(this IMessage message, ByteString data)Merges data from the given byte string into an existing message.
| Parameters | |
|---|---|
| Name | Description |
message |
IMessageThe message to merge the data into. |
data |
ByteStringThe data to merge, which must be protobuf-encoded binary data. |
MergeFrom(IMessage, ReadOnlySequence<byte>)
public static void MergeFrom(this IMessage message, ReadOnlySequence<byte> sequence)Merges data from the given sequence into an existing message.
| Parameters | |
|---|---|
| Name | Description |
message |
IMessageThe message to merge the data into. |
sequence |
ReadOnlySequencebyteSequence from the specified data to merge, which must be protobuf-encoded binary data. |
MergeFrom(IMessage, byte[])
public static void MergeFrom(this IMessage message, byte[] data)Merges data from the given byte array into an existing message.
| Parameters | |
|---|---|
| Name | Description |
message |
IMessageThe message to merge the data into. |
data |
byteThe data to merge, which must be protobuf-encoded binary data. |
MergeFrom(IMessage, byte[], int, int)
public static void MergeFrom(this IMessage message, byte[] data, int offset, int length)Merges data from the given byte array slice into an existing message.
| Parameters | |
|---|---|
| Name | Description |
message |
IMessageThe message to merge the data into. |
data |
byteThe data containing the slice to merge, which must be protobuf-encoded binary data. |
offset |
intThe offset of the slice to merge. |
length |
intThe length of the slice to merge. |
MergeFrom(IMessage, Stream)
public static void MergeFrom(this IMessage message, Stream input)Merges data from the given stream into an existing message.
| Parameters | |
|---|---|
| Name | Description |
message |
IMessageThe message to merge the data into. |
input |
StreamStream containing the data to merge, which must be protobuf-encoded binary data. |
MergeFrom(IMessage, ReadOnlySpan<byte>)
public static void MergeFrom(this IMessage message, ReadOnlySpan<byte> span)Merges data from the given span into an existing message.
| Parameters | |
|---|---|
| Name | Description |
message |
IMessageThe message to merge the data into. |
span |
ReadOnlySpanbyteSpan containing the data to merge, which must be protobuf-encoded binary data. |
ToByteArray(IMessage)
public static byte[] ToByteArray(this IMessage message)Converts the given message into a byte array in protobuf encoding.
| Parameter | |
|---|---|
| Name | Description |
message |
IMessageThe message to convert. |
| Returns | |
|---|---|
| Type | Description |
byte |
The message data as a byte array. |
ToByteString(IMessage)
public static ByteString ToByteString(this IMessage message)Converts the given message into a byte string in protobuf encoding.
| Parameter | |
|---|---|
| Name | Description |
message |
IMessageThe message to convert. |
| Returns | |
|---|---|
| Type | Description |
ByteString |
The message data as a byte string. |
WriteDelimitedTo(IMessage, Stream)
public static void WriteDelimitedTo(this IMessage message, Stream output)Writes the length and then data of the given message to a stream.
| Parameters | |
|---|---|
| Name | Description |
message |
IMessageThe message to write. |
output |
StreamThe output stream to write to. |
WriteTo(IMessage, IBufferWriter<byte>)
public static void WriteTo(this IMessage message, IBufferWriter<byte> output)Writes the given message data to the given buffer writer in protobuf encoding.
| Parameters | |
|---|---|
| Name | Description |
message |
IMessageThe message to write to the stream. |
output |
IBufferWriterbyteThe stream to write to. |
WriteTo(IMessage, Stream)
public static void WriteTo(this IMessage message, Stream output)Writes the given message data to the given stream in protobuf encoding.
| Parameters | |
|---|---|
| Name | Description |
message |
IMessageThe message to write to the stream. |
output |
StreamThe stream to write to. |
WriteTo(IMessage, Span<byte>)
public static void WriteTo(this IMessage message, Span<byte> output)Writes the given message data to the given span in protobuf encoding. The size of the destination span needs to fit the serialized size of the message exactly, otherwise an exception is thrown.
| Parameters | |
|---|---|
| Name | Description |
message |
IMessageThe message to write to the stream. |
output |
SpanbyteThe span to write to. Size must match size of the message exactly. |