Dllb.Protocol (Dllb v0.1.0)

Copy Markdown View Source

Encodes queries to dllb wire format and decodes responses.

The dllb protocol is line-based text over TCP: each query is a string terminated by \n, and each response is a JSON (or toon/csv) line terminated by \n.

Summary

Functions

Decodes a response line received from the server.

Encodes a query string into wire format (iodata) by appending a newline.

Returns the OUTCOME command to send upon connection to set the response format.

Types

format()

@type format() :: :json | :toon | :csv

Functions

decode(line, format \\ :json)

@spec decode(String.t(), format()) :: {:ok, map() | String.t()} | {:error, term()}

Decodes a response line received from the server.

For :json format, parses the line using OTP's built-in :json module. For :toon and :csv, returns the raw string (trimmed) for now.

Returns {:ok, parsed} or {:error, reason}.

encode(query)

@spec encode(String.t()) :: iodata()

Encodes a query string into wire format (iodata) by appending a newline.

outcome_command(atom)

@spec outcome_command(format()) :: iodata()

Returns the OUTCOME command to send upon connection to set the response format.