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

Encodes and decodes awareness (presence) updates in the y-protocols format.
An update starts with its entry count as a varuint. Each entry contains a
client id and clock as varuints, then a length-prefixed JSON state;
`"null"` removes the client's state.

A host can use `decode/1` to check the awareness messages its clients
send, and `encode/1` to build an update from the entries it accepts. The
README's "Authorizing client awareness" section shows how. To publish and
maintain awareness for a server-side participant, use `Slap.Yjs.Presence`.

# `entry`

```elixir
@type entry() ::
  {client_id :: non_neg_integer(), clock :: non_neg_integer(), state :: term()}
```

# `decode`

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

Decodes an awareness update into entries. A removal has a `nil` state.
Returns `{:error, :invalid}` for malformed updates.

A complete awareness message is byte 1 followed by a framed update. This
function accepts only the unframed update.

# `encode`

```elixir
@spec encode([entry()]) :: binary()
```

Encodes entries into an awareness update.

---

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