# serializeBitset

> **serializeBitset**(`set`, `options?`): `Uint8Array`

Defined in: [packages/bitset/src/serialization.ts:123](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/bitset/src/serialization.ts#L123)

Serialize a bitset into canonical binary bytes that restore the same layout.

The payload is the Roaring format’s no-run layout — sorted chunk keys, a cardinality per chunk, then each chunk as a sorted 16-bit id run or a bitmap — inside a `knotkit/wire` envelope. The bytes are Knotkit’s own framing and are not RoaringFormatSpec-compatible.

## Parameters

### set

[`Bitset`](/reference/knotkit/bitset/interfaces/bitset/)

### options?

[`SerializeBitsetOptions`](/reference/knotkit/bitset/wire/interfaces/serializebitsetoptions/)

## Returns

`Uint8Array`

## Throws

With code `FOREIGN_BITSET` when `set` was not produced by this package, or `SERIALIZATION_LIMIT_EXCEEDED` when a `dense` bitset’s bitmap would exceed [BITSET_MAX_DECODE_DENSE_BYTES](/reference/knotkit/bitset/wire/variables/bitset_max_decode_dense_bytes/).
