# Struct WriteContext (3.27.1)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [3.27.1 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WriteContext)
- [3.23.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/3.23.0/Google.Protobuf.WriteContext)
- [3.15.8](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/3.15.8/Google.Protobuf.WriteContext)

    public ref struct WriteContext

An opaque struct that represents the current serialization state and is passed along
as the serialization proceeds.
All the public methods are intended to be invoked only by the generated code,
users should never invoke them directly.

## Inherited Members

[ValueType.Equals(object)](https://learn.microsoft.com/dotnet/api/system.valuetype.equals) [ValueType.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.valuetype.gethashcode) [ValueType.ToString()](https://learn.microsoft.com/dotnet/api/system.valuetype.tostring) [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals)

## Namespace

[Google.Protobuf](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf)

## Assembly

Google.Protobuf.dll

## Methods

### WriteBool(bool)

    public void WriteBool(bool value)

Writes a bool field value, without a tag.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://learn.microsoft.com/dotnet/api/system.boolean` The value to write |

### WriteBytes(ByteString)

    public void WriteBytes(ByteString value)

Write a byte string, without a tag, to the stream.
The data is length-prefixed.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString` The value to write |

### WriteDouble(double)

    public void WriteDouble(double value)

Writes a double field value, without a tag.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://learn.microsoft.com/dotnet/api/system.double` The value to write |

### WriteEnum(int)

    public void WriteEnum(int value)

Writes an enum value, without a tag.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://learn.microsoft.com/dotnet/api/system.int32` The value to write |

### WriteFixed32(uint)

    public void WriteFixed32(uint value)

Writes a fixed32 field value, without a tag.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://learn.microsoft.com/dotnet/api/system.uint32` The value to write |

### WriteFixed64(ulong)

    public void WriteFixed64(ulong value)

Writes a fixed64 field value, without a tag.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://learn.microsoft.com/dotnet/api/system.uint64` The value to write |

### WriteFloat(float)

    public void WriteFloat(float value)

Writes a float field value, without a tag.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://learn.microsoft.com/dotnet/api/system.single` The value to write |

### WriteGroup(IMessage)

    public void WriteGroup(IMessage value)

Writes a group, without a tag, to the stream.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage` The value to write |

### WriteInt32(int)

    public void WriteInt32(int value)

Writes an int32 field value, without a tag.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://learn.microsoft.com/dotnet/api/system.int32` The value to write |

### WriteInt64(long)

    public void WriteInt64(long value)

Writes an int64 field value, without a tag.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://learn.microsoft.com/dotnet/api/system.int64` The value to write |

### WriteLength(int)

    public void WriteLength(int length)

Writes a length (in bytes) for length-delimited data.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `length` | `https://learn.microsoft.com/dotnet/api/system.int32` Length value, in bytes. |

**Remarks** This method simply writes a rawint, but exists for clarity in calling code.

### WriteMessage(IMessage)

    public void WriteMessage(IMessage value)

Writes a message, without a tag.
The data is length-prefixed.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage` The value to write |

### WriteRawTag(byte)

    public void WriteRawTag(byte b1)

Writes the given single-byte tag.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `b1` | `https://learn.microsoft.com/dotnet/api/system.byte` The encoded tag |

### WriteRawTag(byte, byte)

    public void WriteRawTag(byte b1, byte b2)

Writes the given two-byte tag.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `b1` | `https://learn.microsoft.com/dotnet/api/system.byte` The first byte of the encoded tag |
| `b2` | `https://learn.microsoft.com/dotnet/api/system.byte` The second byte of the encoded tag |

### WriteRawTag(byte, byte, byte)

    public void WriteRawTag(byte b1, byte b2, byte b3)

Writes the given three-byte tag.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `b1` | `https://learn.microsoft.com/dotnet/api/system.byte` The first byte of the encoded tag |
| `b2` | `https://learn.microsoft.com/dotnet/api/system.byte` The second byte of the encoded tag |
| `b3` | `https://learn.microsoft.com/dotnet/api/system.byte` The third byte of the encoded tag |

### WriteRawTag(byte, byte, byte, byte)

    public void WriteRawTag(byte b1, byte b2, byte b3, byte b4)

Writes the given four-byte tag.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `b1` | `https://learn.microsoft.com/dotnet/api/system.byte` The first byte of the encoded tag |
| `b2` | `https://learn.microsoft.com/dotnet/api/system.byte` The second byte of the encoded tag |
| `b3` | `https://learn.microsoft.com/dotnet/api/system.byte` The third byte of the encoded tag |
| `b4` | `https://learn.microsoft.com/dotnet/api/system.byte` The fourth byte of the encoded tag |

### WriteRawTag(byte, byte, byte, byte, byte)

    public void WriteRawTag(byte b1, byte b2, byte b3, byte b4, byte b5)

Writes the given five-byte tag.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `b1` | `https://learn.microsoft.com/dotnet/api/system.byte` The first byte of the encoded tag |
| `b2` | `https://learn.microsoft.com/dotnet/api/system.byte` The second byte of the encoded tag |
| `b3` | `https://learn.microsoft.com/dotnet/api/system.byte` The third byte of the encoded tag |
| `b4` | `https://learn.microsoft.com/dotnet/api/system.byte` The fourth byte of the encoded tag |
| `b5` | `https://learn.microsoft.com/dotnet/api/system.byte` The fifth byte of the encoded tag |

### WriteSFixed32(int)

    public void WriteSFixed32(int value)

Writes an sfixed32 value, without a tag.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://learn.microsoft.com/dotnet/api/system.int32` The value to write. |

### WriteSFixed64(long)

    public void WriteSFixed64(long value)

Writes an sfixed64 value, without a tag.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://learn.microsoft.com/dotnet/api/system.int64` The value to write |

### WriteSInt32(int)

    public void WriteSInt32(int value)

Writes an sint32 value, without a tag.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://learn.microsoft.com/dotnet/api/system.int32` The value to write |

### WriteSInt64(long)

    public void WriteSInt64(long value)

Writes an sint64 value, without a tag.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://learn.microsoft.com/dotnet/api/system.int64` The value to write |

### WriteString(string)

    public void WriteString(string value)

Writes a string field value, without a tag.
The data is length-prefixed.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://learn.microsoft.com/dotnet/api/system.string` The value to write |

### WriteTag(int, WireType)

    public void WriteTag(int fieldNumber, WireFormat.WireType type)

Encodes and writes a tag.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `fieldNumber` | `https://learn.microsoft.com/dotnet/api/system.int32` The number of the field to write the tag for |
| `type` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WireFormathttps://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WireFormat.WireType` The wire format type of the tag to write |

### WriteTag(uint)

    public void WriteTag(uint tag)

Writes an already-encoded tag.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `tag` | `https://learn.microsoft.com/dotnet/api/system.uint32` The encoded tag |

### WriteUInt32(uint)

    public void WriteUInt32(uint value)

Writes a uint32 value, without a tag.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://learn.microsoft.com/dotnet/api/system.uint32` The value to write |

### WriteUInt64(ulong)

    public void WriteUInt64(ulong value)

Writes a uint64 field value, without a tag.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://learn.microsoft.com/dotnet/api/system.uint64` The value to write |