# `XMediaLib.SDP.Encoder`
[🔗](https://github.com/Lazarus404/xmedialib/blob/main/lib/sdp/encoder.ex#L25)

Encodes `%XMediaLib.SDP{}` to wire-format SDP.

## What problem this solves

After negotiating or modifying a session in memory, you must serialize
`%XMediaLib.SDP{}` back to wire text for SIP bodies or WebRTC signaling. Each
line prefix (`v=`, `o=`, `m=`, `a=`) and CRLF rule comes from RFC 8866.
This module performs that serialization; callers usually invoke
`XMediaLib.SDP.encode/1`.

Serializes session-level lines first (`v=`, `o=`, `s=`, `c=`, `t=`, groups,
session attributes), then each `%XMediaLib.SDP.Media{}` block in list order.
Output uses CRLF line endings as commonly seen on the wire and in browser
offer/answer text.

Prefer `XMediaLib.SDP.encode/1` at application boundaries; use this module
when encoding from tests or internal pipelines that already hold a parsed struct.

## RFCs

* [RFC 8866](https://www.rfc-editor.org/rfc/rfc8866) - SDP line formats
* [RFC 8445](https://www.rfc-editor.org/rfc/rfc8445) - ICE attribute encoding
* [RFC 8122](https://www.rfc-editor.org/rfc/rfc8122) - fingerprint/setup
* [RFC 8841](https://www.rfc-editor.org/rfc/rfc8841) - SCTP/data channel attributes

# `encode`

```elixir
@spec encode(XMediaLib.SDP.t()) :: {:ok, binary()} | {:error, term()}
```

Serializes a session description to SDP bytes.

Returns `{:ok, binary()}` on success or `{:error, :encoding_failed}` if an
unexpected value prevents serialization.

## Examples

    iex> sdp = %XMediaLib.SDP{version: 0, session_name: "-", time: [%XMediaLib.SDP.Time{}]}
    iex> {:ok, bin} = XMediaLib.SDP.Encoder.encode(sdp)
    iex> String.starts_with?(bin, "v=0")
    true

---

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