View Source Baby.Util (Baby v0.32.0)

Utility functions for use across the codebase

Summary

Functions

Standardised connection activity logging for the supplied state dir: :in, :out, :both msg: a protocol message type atom level: log lvel atom (default: :debug)

A simple wrapper to convert a host binary into an IP tuple

Logging of fatal errors takes connection info and the error

Convert a {count, unit} period into a number of milliseconds

Returns tuples of the endpoints of the widest continuous ranges in a list of integers

Functions

Link to this function

connection_log(conn_info, dir, msg, level \\ :debug)

View Source

Standardised connection activity logging for the supplied state dir: :in, :out, :both msg: a protocol message type atom level: log lvel atom (default: :debug)

A simple wrapper to convert a host binary into an IP tuple

Link to this function

log_fatal(conn_info, error)

View Source

Logging of fatal errors takes connection info and the error

Returns :error

@spec period_to_ms({integer(), atom()}) :: integer() | :error

Convert a {count, unit} period into a number of milliseconds

Examples

 iex> Baby.Util.period_to_ms({1, :hour})
 3_600_000


 iex> Baby.Util.period_to_ms({17, :minute})
 1_020_000

Returns tuples of the endpoints of the widest continuous ranges in a list of integers

iex> Baby.Util.range_points([8, 2, 5, 4, 3, 10, 11, 16, 17])
[{2, 5}, {8, 8}, {10, 11}, {16, 17}]

iex> Baby.Util.range_points([127])
[{127, 127}]

iex> Baby.Util.range_points([])
[]