Gamend.Hooks.KvSchemas (gamend_core v1.0.1192)

Copy Markdown View Source

Registry of game-defined protobuf schemas for KV entry data.

KV keys are open-ended, so unlike metadata entities there is no naming convention — a plugin registers schemas explicitly by exporting kv_schemas/0, mapping exact keys or *-suffixed prefixes to protobuf message modules:

def kv_schemas do
  %{
    "loadout" => MyGame.V1.Loadout,
    "match:*" => MyGame.V1.MatchState
  }
end

On protobuf sockets, kv_updated data for a matching key is pushed as compact binary (data_pb) instead of JSON bytes; storage and REST stay JSON, and data that does not fit the schema falls back to JSON so it is never dropped. Exact keys win over prefixes; the longest prefix wins. KV entry metadata always stays JSON.

The KV keyspace is global: when two plugins register the same key or prefix pattern, the first plugin in name order wins and the losing registration is logged.

Summary

Functions

Returns the full registry (for the admin overview).

Returns the registered schema module for a KV key, or nil.

Rebuilds the registry from the loaded plugin list.

Functions

all()

@spec all() :: %{
  exact: %{required(String.t()) => module()},
  prefixes: [{String.t(), module()}]
}

Returns the full registry (for the admin overview).

module_for(key)

@spec module_for(String.t()) :: module() | nil

Returns the registered schema module for a KV key, or nil.

refresh(plugins)

@spec refresh([struct()]) :: :ok

Rebuilds the registry from the loaded plugin list.