> For the complete documentation index, see [llms.txt](https://kinematicsoup.gitbook.io/reactor/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinematicsoup.gitbook.io/reactor/api-reference/ks.reactor/ks.reactor.ksfixeddatawriter.md).

# Class ksFixedDataWriter

Namespace: [KS.Reactor](/reactor/api-reference/ks.reactor.md)\
Assembly: KSCommon.dll

A class that writes uint or struct to a byte array.

```csharp
public class ksFixedDataWriter
```

#### Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) ← [ksFixedDataWriter](/reactor/api-reference/ks.reactor/ks.reactor.ksfixeddatawriter.md)

#### Inherited Members

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

## Fields

### ENCODE\_1BYTE <a href="#ks_reactor_ksfixeddatawriter_encode_1byte" id="ks_reactor_ksfixeddatawriter_encode_1byte"></a>

```csharp
public const uint ENCODE_1BYTE = 127
```

#### Field Value

[uint](https://learn.microsoft.com/dotnet/api/system.uint32)

### ENCODE\_2BYTE <a href="#ks_reactor_ksfixeddatawriter_encode_2byte" id="ks_reactor_ksfixeddatawriter_encode_2byte"></a>

```csharp
public const uint ENCODE_2BYTE = 16383
```

#### Field Value

[uint](https://learn.microsoft.com/dotnet/api/system.uint32)

### ENCODE\_4BYTE <a href="#ks_reactor_ksfixeddatawriter_encode_4byte" id="ks_reactor_ksfixeddatawriter_encode_4byte"></a>

```csharp
public const uint ENCODE_4BYTE = 1073741823
```

#### Field Value

[uint](https://learn.microsoft.com/dotnet/api/system.uint32)

## Methods

### WriteData\<T>(byte\[], int, int, T) <a href="#ks_reactor_ksfixeddatawriter_writedata__1_system_byte___system_int32_system_int32___0" id="ks_reactor_ksfixeddatawriter_writedata__1_system_byte___system_int32_system_int32___0"></a>

Write data to a byte array.

```csharp
public static int WriteData<T>(byte[] output, int spaceAvailable, int offset, T data) where T : struct
```

#### Parameters

`output` [byte](https://learn.microsoft.com/dotnet/api/system.byte)\[]

Output byte array.

`spaceAvailable` [int](https://learn.microsoft.com/dotnet/api/system.int32)

Amount of space available for writing.

`offset` [int](https://learn.microsoft.com/dotnet/api/system.int32)

Offset to begin writing at.

`data` T

Data to write.

#### Returns

[int](https://learn.microsoft.com/dotnet/api/system.int32)

Number of bytes written, or -1 on an error.

#### Type Parameters

`T`

Type of data to write.

### WriteEncodedUInt(byte\[], int, int, uint) <a href="#ks_reactor_ksfixeddatawriter_writeencodeduint_system_byte___system_int32_system_int32_system_uint32" id="ks_reactor_ksfixeddatawriter_writeencodeduint_system_byte___system_int32_system_int32_system_uint32"></a>

Write a uint as an encoded value. This value must be less than 2^30 The lowest bit positions of the encoded value signal the number of bytes to read. If the value is less than or equal to 2^7-1, the first bit is a 0 and the value is placed in bits 1 to 7. If the value is less than or equal to 2^14-1, the first two bits are 01 and the value is placed in bits 2 to 15. If the value is less than or equal to 2^30-1, the first two bits are 11 and the value is placed in bits 2 to 31.

```csharp
public static int WriteEncodedUInt(byte[] output, int spaceAvailable, int offset, uint value)
```

#### Parameters

`output` [byte](https://learn.microsoft.com/dotnet/api/system.byte)\[]

Output byte array.

`spaceAvailable` [int](https://learn.microsoft.com/dotnet/api/system.int32)

Amount of space available for writing.

`offset` [int](https://learn.microsoft.com/dotnet/api/system.int32)

Offset to begin writing at.

`value` [uint](https://learn.microsoft.com/dotnet/api/system.uint32)

Value to write.

#### Returns

[int](https://learn.microsoft.com/dotnet/api/system.int32)

Number of bytes written, or -1 on an error
