FakeRiak.Protocol behaviour (fake_riak v0.1.0)

Copy Markdown View Source

Behaviour implemented by every wire-protocol handler (Riak, Redis, etcd, memcached).

A handler is a pure request parser driven by FakeRiak.Connection:

  • init/0 returns the initial per-connection parser state.

  • parse/2 is handed the bytes received so far plus the current state and returns one of:

    • {:reply, response, rest, state} — a complete request was parsed; response (iodata) is sent back and parsing continues on rest.
    • {:need_more, state} — the buffer does not yet contain a full request; the loop reads more bytes and calls parse/2 again.
    • {:close, response} — send the (possibly empty) response and close the connection.

Summary

Types

result()

@type result() ::
  {:reply, iodata(), binary(), state()}
  | {:need_more, state()}
  | {:close, iodata()}

state()

@type state() :: term()

Callbacks

init()

@callback init() :: state()

parse(buffer, state)

@callback parse(buffer :: binary(), state()) :: result()