# MessageConfig

`MessageConfig` allows you to configure settings for message communication within Tarnet. Settings like message compression and buffer size help manage data transmission efficiently. These configurations are critical for optimizing data size and enhancing performance during transmission.

***

**Properties**

* **`compression`**
  * Type: `bool`
  * Description: Enables or disables message compression to reduce the size of data during transmission.
  * **What does it do?**\
    When enabled, message compression reduces the size of the data being transmitted, which helps optimize bandwidth usage. This is especially useful for projects that frequently transmit large amounts of data, reducing network traffic and improving performance.
  * **How it works:**\
    Messages are compressed before being sent and decompressed on the receiving end. This process is handled automatically using compression algorithms.
  * Default Value: `false`
* **`bufferSize`**
  * Type: `int`
  * Description: Defines the size of the buffer (in bytes) used for message handling.
  * **What does it do?**\
    The buffer size determines the amount of memory allocated for handling messages before they are transmitted or processed. A larger buffer size allows longer messages to be processed in a single operation, but it also increases memory usage.
  * **How it works:**\
    Incoming and outgoing messages are processed in the buffer. The buffer size helps prevent large messages from being fragmented and ensures faster processing. However, the buffer size should be adjusted according to the specific requirements of the project.
  * Default Value: `1024` (1 KB)

***

**How to Create MessageConfig**

1. **Through the Unity Editor**\
   Navigate to **Assets > Create > Tarnet > MessageConfig** to create a new `MessageConfig` instance.

<figure><img src="/files/PdjdgFsTBDqoCE8WEYlG" alt=""><figcaption></figcaption></figure>

2. **Through Code**

```csharp
MessageConfig messageConfig = ScriptableObject.CreateInstance<MessageConfig>();
messageConfig.compression = true;
messageConfig.bufferSize = 2048;
```

***

**Usages:**

`MessageConfig` is configured and used through the **SocketBuilder** class. Below is an example of how to integrate it using the `SetMessageConfig` method:

```csharp
socketBuilder.SetMessageConfig(messageConfig);
```

***

These configurations ensure maximum efficiency in network communication built with Tarnet. By setting the appropriate values for your project, you can create a faster, more reliable, and optimized communication infrastructure.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tariksavas.gitbook.io/tarnet/docs/how-to-use/configurations/messageconfig.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
