---
url: https://docs.moqtail.dev/ts/api/model/classes/Tuple.md
---
# Class: Tuple

Represents a sequence of TupleFields, typically used for hierarchical paths or protocol tuples in MOQT.

## Constructors

### Constructor

> **new Tuple**(`fields?`): `Tuple`

The ordered list of fields in this tuple.

#### Parameters

##### fields?

[`TupleField`](TupleField.md)\[] = `[]`

#### Returns

`Tuple`

## Properties

### fields

> `readonly` **fields**: [`TupleField`](TupleField.md)\[] = `[]`

## Methods

### add()

> **add**(`field`): `void`

Adds a field to the tuple.

#### Parameters

##### field

[`TupleField`](TupleField.md)

The TupleField to add.

#### Returns

`void`

***

### clear()

> **clear**(): `void`

Clears all fields from the tuple.

#### Returns

`void`

***

### equals()

> **equals**(`other`): `boolean`

Checks if this tuple is equal to another.

#### Parameters

##### other

`Tuple`

The other Tuple to compare.

#### Returns

`boolean`

True if all fields are equal.

***

### get()

> **get**(`index`): [`TupleField`](TupleField.md)

Gets the field at the specified index.

#### Parameters

##### index

`number`

The field index.

#### Returns

[`TupleField`](TupleField.md)

The TupleField at the index.

#### Throws

Error if no field exists at the index.

***

### serialize()

> **serialize**(): [`FrozenByteBuffer`](FrozenByteBuffer.md)

Serializes the tuple to a FrozenByteBuffer.

#### Returns

[`FrozenByteBuffer`](FrozenByteBuffer.md)

The serialized buffer.

***

### set()

> **set**(`index`, `field`): `void`

Sets the field at the specified index.

#### Parameters

##### index

`number`

The field index.

##### field

[`TupleField`](TupleField.md)

The TupleField to set.

#### Returns

`void`

***

### toUtf8Path()

> **toUtf8Path**(): `string`

Converts the tuple to a path string, joining fields with '/'.

#### Returns

`string`

The path string (e.g. '/foo/bar').

***

### deserialize()

> `static` **deserialize**(`buf`): `Tuple`

Deserializes a Tuple from a buffer.

#### Parameters

##### buf

[`BaseByteBuffer`](BaseByteBuffer.md)

The buffer to read from.

#### Returns

`Tuple`

The deserialized Tuple.

#### Throws

CastingError if the count cannot be safely cast to number.

#### Throws

NotEnoughBytesError if buffer does not contain enough bytes.

***

### fromUtf8Path()

> `static` **fromUtf8Path**(`path`): `Tuple`

Creates a Tuple from a path string, splitting on '/'.

#### Parameters

##### path

`string`

The path string (e.g. '/foo/bar').

#### Returns

`Tuple`

A Tuple with each segment as a field.
