# `Slap.Yjs.Frame`
[🔗](https://github.com/mjrusso/slap/blob/slap_yjs-v0.3.0/slap_yjs/lib/slap/yjs/frame.ex#L1)

The framing of Yjs updates in a `.updates` stream, as lib0's
`writeVarUint8Array` writes it and the reference `y-durable-streams`
provider reads it: each update is its byte size as a varuint, then the
update. Frames are concatenated, so a batch of frames is itself valid
framing.

A varuint is little-endian base 128: 7 bits per byte, low groups first,
the high bit set on every byte but the last.

# `frame`

```elixir
@spec frame(binary()) :: binary()
```

Frames one update.

# `frames`

```elixir
@spec frames([binary()]) :: binary()
```

Frames several updates into one binary.

# `parse`

```elixir
@spec parse(binary()) :: {:ok, [binary()]} | {:error, :truncated | :invalid}
```

Splits concatenated frames into their updates. `{:error, :truncated}` if
the binary ends inside a frame, `{:error, :invalid}` if a length does not
fit in 53 bits (lib0's limit).

# `read_varuint`

```elixir
@spec read_varuint(binary()) ::
  {:ok, non_neg_integer(), binary()} | {:error, :truncated | :invalid}
```

Decodes a varuint at the start of `binary`: `{:ok, n, rest}`, or an error
as for `parse/1`.

# `varuint`

```elixir
@spec varuint(non_neg_integer()) :: binary()
```

Encodes a non-negative integer as a varuint.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
