khepri_payload (khepri v0.6.0)

Khepri payloads.

Payloads are the structure used to attach something to a tree node in the store. Khepri supports the following payloads:
  • No payload at all (no_payload()
  • Data payload used to store any Erlang term (data())
  • Stored procedure payload used to store functions (sproc())
Usually, there is no need to explicitly use this module as the type of payload will be autodetected, thanks to the wrap/1 function already called internally.

Link to this section Summary

Types

Internal structure to wrap any Erlang term before it can be stored in a tree node.

Internal value used to mark that a tree node has no payload attached.

All types of payload stored in the nodes of the tree structure.

Internal structure to wrap an anonymous function before it can be stored in a tree node and later executed.

Functions

Returns the same term wrapped into an internal structure ready to be stored in the tree.

See also: data().

Returns the internal value used to mark that a tree node has no payload attached.

See also: no_payload().

Returns the same function wrapped into an internal structure ready to be stored in the tree.

See also: sproc().

Automatically detects the payload type and ensures it is wrapped in one of the internal types.

Link to this section Types

-type data() :: #p_data{}.

Internal structure to wrap any Erlang term before it can be stored in a tree node.

The only constraint is the conversion to an Erlang binary must be supported by this term.
Link to this type

no_payload/0

-type no_payload() :: '$__NO_PAYLOAD__'.
Internal value used to mark that a tree node has no payload attached.
-type payload() :: no_payload() | data() | sproc().

All types of payload stored in the nodes of the tree structure.

Beside the absence of payload, the only type of payload supported is data.
-type sproc() :: #p_sproc{}.
Internal structure to wrap an anonymous function before it can be stored in a tree node and later executed.

Link to this section Functions

-spec data(Term) -> Payload when Term :: khepri:data(), Payload :: data().
Returns the same term wrapped into an internal structure ready to be stored in the tree.

See also: data().

-spec none() -> no_payload().
Returns the internal value used to mark that a tree node has no payload attached.

See also: no_payload().

-spec sproc(Fun) -> Payload when Fun :: khepri_fun:standalone_fun() | fun(), Payload :: sproc().
Returns the same function wrapped into an internal structure ready to be stored in the tree.

See also: sproc().

-spec wrap(Payload) -> WrappedPayload
        when Payload :: payload() | khepri:data() | fun(), WrappedPayload :: payload().

Automatically detects the payload type and ensures it is wrapped in one of the internal types.

The internal types make sure we avoid any collision between any user-provided terms and internal structures.