Ferricstore.Resp.Parser (ferricstore v0.4.3)

Copy Markdown View Source

Rust NIF parser for the RESP3 protocol.

Parses a binary buffer containing one or more RESP3-encoded values and returns all complete values along with any unparsed remainder. This module owns the public RESP parser API; parsing itself is performed by Ferricstore.Resp.ParserNif.

Supported RESP3 types

PrefixTypeElixir representation
+Simple string{:simple, binary()}
-Simple error{:error, binary()}
:Integerinteger()
$Bulk stringbinary() or nil for $-1
*Arraylist() or nil for *-1
_Nullnil
#Booleantrue or false

| , | Double | float() or :infinity | :neg_infinity | :nan | | ( | Big number | integer() | | ! | Blob error | {:error, binary()} | | = | Verbatim string | {:verbatim, encoding, data} | | % | Map | map() | | ~ | Set | MapSet.t() | | > | Push | {:push, list()} | | | | Attribute | {:attribute, map()} |

Inline commands (plain text terminated by \r\n) are returned as {:inline, [binary()]}.

Bulk-like payload length is checked at parse time against a configurable maximum (:max_value_size in Application env, default 1 MB). A hard cap of 64 MB is enforced regardless of the configured value.

Summary

Functions

Returns the default maximum value size in bytes (1 MB).

Returns the hard cap on bulk-like payload length in bytes (64 MB).

Parses a binary buffer containing RESP3-encoded data.

Parses a binary buffer with an explicit maximum bulk-like payload size.

Parses server command frames into normalized command tuples in Rust.

Parses server command frames with an explicit maximum command argument size.

Types

command_ast()

@type command_ast() :: tuple()

parse_commands_result()

@type parse_commands_result() ::
  {:ok, [parsed_command()], binary()} | {:error, term()}

parse_result()

@type parse_result() :: {:ok, [parsed_value()], binary()} | {:error, term()}

parsed_command()

@type parsed_command() :: {:command, binary(), [binary()], command_ast(), [binary()]}

parsed_value()

@type parsed_value() ::
  {:simple, binary()}
  | {:error, binary()}
  | integer()
  | binary()
  | nil
  | boolean()
  | float()
  | :infinity
  | :neg_infinity
  | :nan
  | {:verbatim, binary(), binary()}
  | map()
  | MapSet.t()
  | {:push, list()}
  | {:attribute, map()}
  | {:inline, [binary()]}
  | list()

Functions

default_max_value_size()

@spec default_max_value_size() :: pos_integer()

Returns the default maximum value size in bytes (1 MB).

hard_cap_bytes()

@spec hard_cap_bytes() :: pos_integer()

Returns the hard cap on bulk-like payload length in bytes (64 MB).

parse(data)

@spec parse(binary()) :: parse_result()

Parses a binary buffer containing RESP3-encoded data.

parse(data, max_value_size)

@spec parse(binary(), non_neg_integer()) :: parse_result()

Parses a binary buffer with an explicit maximum bulk-like payload size.

parse_commands(data)

@spec parse_commands(binary()) :: parse_commands_result()

Parses server command frames into normalized command tuples in Rust.

Command names are uppercased in the NIF. Arguments remain binary sub-binaries of the input buffer. RESP arrays must contain bulk-string command arguments; inline commands are split on spaces and tabs.

parse_commands(data, max_value_size)

@spec parse_commands(binary(), non_neg_integer()) :: parse_commands_result()

Parses server command frames with an explicit maximum command argument size.