RPC¶
Remote procedure calls are opaque byte payloads routed by target and delivered through the
on_rpc callback during tick. An RPC always names a specific
object (netid); for the object-less sibling see Custom events.
lattice_rpc¶
LATTICE_API lattice_result lattice_rpc(lattice_runner* r, lattice_netid id, uint16_t rpc_id,
lattice_rpc_target target, const uint8_t* payload,
uint32_t len, int reliable);
Send an RPC. Role: both (a client implicitly targets the server).
| Param | Meaning |
|---|---|
id |
The object the RPC is about (its netid). |
rpc_id |
Your typed RPC tag, delivered verbatim to on_rpc. |
target |
A lattice_rpc_target fan-out policy. |
payload / len |
Arbitrary serialized bytes (e.g. from a lattice_bw_* writer); may be NULL when len == 0. Delivered byte-exact; copied by the core. |
reliable |
Non-zero ⇒ reliable, ordered delivery; zero ⇒ best-effort. |
Returns: LATTICE_OK on accept, or an error (e.g. LATTICE_ERR_NOT_CONNECTED for a client
with no session, LATTICE_ERR_UNKNOWN_OBJECT).
lattice_rpc_target¶
typedef enum {
LATTICE_RPC_SERVER = 0, /* client -> authority */
LATTICE_RPC_OWNER, /* authority -> the object's owner */
LATTICE_RPC_ALL, /* authority -> every peer */
LATTICE_RPC_ALL_BUT_OWNER /* authority -> every peer except the owner */
} lattice_rpc_target;
Example¶
/* Client -> server: */
const uint8_t ping[4] = {'p','i','n','g'};
lattice_rpc(r, nid, /*rpc_id*/7, LATTICE_RPC_SERVER, ping, 4, /*reliable*/1);
/* Server -> everyone: */
const uint8_t pong[4] = {'p','o','n','g'};
lattice_rpc(r, nid, /*rpc_id*/9, LATTICE_RPC_ALL, pong, 4, /*reliable*/1);
Receiving side — the callback fires inside tick; do no blocking work:
static void on_rpc(void* user, lattice_netid id, uint16_t rpc_id,
const uint8_t* payload, uint32_t len) {
/* dispatch on rpc_id; payload/len is owned by the core for the call only */
}
RPC vs. event
Use an RPC when the message is about a specific object you have a netid for. Use a
custom event for object-less / session-scoped messages (chat, match state,
a global ping) — it shares the same fan-out policy but doesn't require a netid.