# `VerifiedPubSub.Payload`
[🔗](https://github.com/CuriousCurmudgeon/verified_pubsub/blob/v0.1.0/lib/verified_pubsub/payload.ex#L1)

Validates the payload of each broadcast against the manifest at runtime.

The check runs on each broadcast, in each environment. It costs one pass over the
declared fields and one comparison of key sets. That cost is small next to the send to
`Phoenix.PubSub` that it guards.

# `valid_field?`

```elixir
@spec valid_field?(VerifiedPubSub.Dsl.Field.t(), term()) :: boolean()
```

Whether `value` satisfies `field`.

An optional field accepts `nil`, because Elixir and Ecto use `nil` for an absent value. A
payload that comes from a struct holds every key, so a rule to leave out the key would be
hard to meet. A required field rejects `nil`.

# `validate!`

```elixir
@spec validate!(module(), atom(), atom(), term()) :: term()
```

Checks `payload` against the fields that the manifest declares for `{topic, event}`.

Raises `VerifiedPubSub.PayloadError` on any mismatch. Returns the payload unchanged, so
a caller can use the call inline.

---

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