# `Caracola.Serializer`
[🔗](https://github.com/netkubes/caracola/blob/v0.1.0-rc.1/lib/caracola/serializer.ex#L1)

SIP message serializer. Port of NkSIP's `nksip_unparse`.

Headers are written in a fixed order (Via, From, To, Call-ID, CSeq,
Max-Forwards, Content-Length, Route, Contact, Content-Type, Require,
Supported, Expires, Event), followed by the rest in their original order.
`Content-Length` is always computed from the body.

# `encode`

```elixir
@spec encode(Caracola.Message.t()) :: binary()
```

Serializes a message.

# `error_response`

```elixir
@spec error_response(Caracola.ParseError.t()) :: {:ok, binary()} | :error
```

Builds the `400 Invalid <header>` response for a request that failed parsing,
copying the Via, From, To, Call-ID and CSeq headers from the raw request.

Returns `:error` if the start line could not be parsed or it was a response,
since then no reply must be sent.

# `reason_phrase`

```elixir
@spec reason_phrase(100..699) :: String.t()
```

Standard reason phrase for a response code.

    iex> Caracola.Serializer.reason_phrase(486)
    "Busy Here"

# `to_iodata`

```elixir
@spec to_iodata(Caracola.Message.t()) :: iodata()
```

Serializes a message as iodata.

---

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