FauxRedis.RESP (faux_redis v1.0.3)

Copy Markdown View Source

Minimal RESP2 encoder/decoder used by FauxRedis.

This module is intentionally self-contained and does not depend on the rest of the application. It operates purely on binaries and iodata.

Supported types:

  • simple strings – {:simple_string, binary} or the atom :ok
  • errors – {:error, binary} or {:error, :noauth} etc.
  • integers – {:integer, integer} or plain integers
  • bulk strings – {:bulk, binary | nil} or plain binaries / nil

  • arrays – {:array, list} or plain lists

The parser understands all of these forms and returns Elixir values:

  • simple string → binary
  • error → {:error, binary}
  • integer → integer
  • bulk → binary | nil

  • array → list

Summary

Functions

Decodes a single RESP value from the given binary.

Convenience function for decoding exactly one value and asserting that the buffer has been fully consumed.

Encodes a value into RESP iodata.

Types

decoded()

@type decoded() :: binary() | {:error, binary()} | integer() | nil | [decoded()]

Functions

decode(arg1)

@spec decode(binary()) :: {:ok, decoded(), binary()} | :more | {:error, term()}

Decodes a single RESP value from the given binary.

Returns:

  • {:ok, value, rest} – successfully decoded one value
  • :more – more data is required
  • {:error, reason} – malformed input

decode_exactly(binary)

@spec decode_exactly(binary()) :: {:ok, decoded()} | :more | {:error, term()}

Convenience function for decoding exactly one value and asserting that the buffer has been fully consumed.

encode(int)

@spec encode(term()) :: iodata()

Encodes a value into RESP iodata.

Accepted forms:

  • binary – bulk string
  • nil – null bulk string
  • integer – integer reply
  • list – array
  • {:error, message} – error reply
  • {:simple_string, message} – simple string
  • :ok – simple string "OK"