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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThis document outlines the \u003ccode\u003eMessageExtensions\u003c/code\u003e class, which provides extension methods for \u003ccode\u003eIMessage\u003c/code\u003e and \u003ccode\u003eIMessage<T>\u003c/code\u003e within the \u003ccode\u003eGoogle.Protobuf\u003c/code\u003e namespace.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eIsInitialized\u003c/code\u003e method verifies if all required fields in a message have been assigned values, but returns true for proto3 messages.\u003c/p\u003e\n"],["\u003cp\u003eSeveral \u003ccode\u003eMergeFrom\u003c/code\u003e methods are provided to merge protobuf-encoded binary data from various sources like \u003ccode\u003eByteString\u003c/code\u003e, \u003ccode\u003eReadOnlySequence\u003c/code\u003e, \u003ccode\u003ebyte[]\u003c/code\u003e, \u003ccode\u003eStream\u003c/code\u003e, and \u003ccode\u003eReadOnlySpan\u003c/code\u003e into an existing message.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eToByteArray\u003c/code\u003e and \u003ccode\u003eToByteString\u003c/code\u003e methods facilitate the conversion of a message into a byte array or byte string, respectively, using protobuf encoding.\u003c/p\u003e\n"],["\u003cp\u003eMultiple \u003ccode\u003eWriteTo\u003c/code\u003e methods, including \u003ccode\u003eWriteDelimitedTo\u003c/code\u003e, allow writing message data to different output types such as a \u003ccode\u003eStream\u003c/code\u003e, \u003ccode\u003eSpan<byte>\u003c/code\u003e, or \u003ccode\u003eIBufferWriter<byte>\u003c/code\u003e, using protobuf encoding.\u003c/p\u003e\n"]]],[],null,["# Class MessageExtensions (3.27.1)\n\nVersion latestkeyboard_arrow_down\n\n- [3.27.1 (latest)](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageExtensions)\n- [3.23.0](/dotnet/docs/reference/Google.Protobuf/3.23.0/Google.Protobuf.MessageExtensions)\n- [3.15.8](/dotnet/docs/reference/Google.Protobuf/3.15.8/Google.Protobuf.MessageExtensions) \n\n public static class MessageExtensions\n\nExtension methods on [IMessage](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage) and [IMessage\\\u003cT\\\u003e](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage-1). \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e MessageExtensions \n\nInherited Members\n-----------------\n\n[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) \n[object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) \n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) \n[object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) \n[object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)\n\nNamespace\n---------\n\n[Google.Protobuf](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf)\n\nAssembly\n--------\n\nGoogle.Protobuf.dll\n\nMethods\n-------\n\n### IsInitialized(IMessage)\n\n public static bool IsInitialized(this IMessage message)\n\nChecks if all required fields in a message have values set. For proto3 messages, this returns true.\n\n### MergeDelimitedFrom(IMessage, Stream)\n\n public static void MergeDelimitedFrom(this IMessage message, Stream input)\n\nMerges length-delimited data from the given stream into an existing message.\n\n**Remarks** \nThe stream is expected to contain a length and then the data. Only the amount of data\nspecified by the length will be consumed.\n\n### MergeFrom(IMessage, ByteString)\n\n public static void MergeFrom(this IMessage message, ByteString data)\n\nMerges data from the given byte string into an existing message.\n\n### MergeFrom(IMessage, ReadOnlySequence\\\u003cbyte\\\u003e)\n\n public static void MergeFrom(this IMessage message, ReadOnlySequence\u003cbyte\u003e sequence)\n\nMerges data from the given sequence into an existing message.\n\n### MergeFrom(IMessage, byte\\[\\])\n\n public static void MergeFrom(this IMessage message, byte[] data)\n\nMerges data from the given byte array into an existing message.\n\n### MergeFrom(IMessage, byte\\[\\], int, int)\n\n public static void MergeFrom(this IMessage message, byte[] data, int offset, int length)\n\nMerges data from the given byte array slice into an existing message.\n\n### MergeFrom(IMessage, Stream)\n\n public static void MergeFrom(this IMessage message, Stream input)\n\nMerges data from the given stream into an existing message.\n\n### MergeFrom(IMessage, ReadOnlySpan\\\u003cbyte\\\u003e)\n\n public static void MergeFrom(this IMessage message, ReadOnlySpan\u003cbyte\u003e span)\n\nMerges data from the given span into an existing message.\n\n### ToByteArray(IMessage)\n\n public static byte[] ToByteArray(this IMessage message)\n\nConverts the given message into a byte array in protobuf encoding.\n\n### ToByteString(IMessage)\n\n public static ByteString ToByteString(this IMessage message)\n\nConverts the given message into a byte string in protobuf encoding.\n\n### WriteDelimitedTo(IMessage, Stream)\n\n public static void WriteDelimitedTo(this IMessage message, Stream output)\n\nWrites the length and then data of the given message to a stream.\n\n### WriteTo(IMessage, IBufferWriter\\\u003cbyte\\\u003e)\n\n public static void WriteTo(this IMessage message, IBufferWriter\u003cbyte\u003e output)\n\nWrites the given message data to the given buffer writer in protobuf encoding.\n\n### WriteTo(IMessage, Stream)\n\n public static void WriteTo(this IMessage message, Stream output)\n\nWrites the given message data to the given stream in protobuf encoding.\n\n### WriteTo(IMessage, Span\\\u003cbyte\\\u003e)\n\n public static void WriteTo(this IMessage message, Span\u003cbyte\u003e output)\n\nWrites the given message data to the given span in protobuf encoding.\nThe size of the destination span needs to fit the serialized size\nof the message exactly, otherwise an exception is thrown."]]