Caracola.Serializer (Caracola v0.1.0-rc.1)

Copy Markdown View Source

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.

Summary

Functions

Serializes a message.

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.

Standard reason phrase for a response code.

Serializes a message as iodata.

Functions

encode(msg)

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

Serializes a message.

error_response(parse_error)

@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(code)

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

Standard reason phrase for a response code.

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

to_iodata(msg)

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

Serializes a message as iodata.