Skip to main content

Module envelope

Module envelope 

Source
Expand description

Envelopes (specification §7) and error bodies (§11).

Bodies stay raw JSON (RawValue) here: the command and event modules parse them by type, and the idempotency body hash (§7.3) is taken over the body text exactly as received.

Structs§

BodyHash
SHA3-256 of a command’s body JSON text exactly as received (§7.3): reformatting the same JSON gives a different hash, which is why retries must resend byte-identical bodies.
CommandEnvelope
{ "v", "type", "request_id", "community_id", "channel_id"?, "body" } (§7.1).
ErrorBody
An error object: code, message, and the code’s extra fields placed next to code (§7.2, §11). Build it with the constructors (one per ErrorCode, see errors.rs); they use fixed messages so no secret, connection detail, member key or other member’s data can reach the wire (§11). The extras are boxed to keep Result<_, ErrorBody> small.
ErrorExtras
The extra fields of §11. Each applies to the codes named on it.
EventEnvelope
{ "v", "type", "community_id", "channel_id"?, "stream", "sequence"?, "timestamp", "actor_id", "body" } (§7.4). Deserialisation validates with EventEnvelope::validate.
EventsBatch
A validated events batch. Its events are processed in order, exactly as individual events (§10.5); the batch itself has no stream, sequence or timestamp.
Rejection
A command the host rejects before dispatch; send Rejection::into_response back.
ResponseEnvelope
{ "v", "type": "response", "request_id", "ok", "body" | "error" } (§7.2).
VersionRange
An inclusive protocol version range (session.hello.versions, UNSUPPORTED_VERSION).

Enums§

BatchError
A batch that breaks the rules of §10.5. Indices count from 0 in body.events.
EventError
An event envelope that breaks the rules of §7.4.
IdempotencyKey
The key an idempotency record is stored under (§7.3). C is the host’s opaque connection id, used only for unbound connections.
Outcome
The result carried by a response.
RateCategory
RATE_LIMITED category (§11).
RateScope
RATE_LIMITED scope (§11).
Reason
FORBIDDEN and CONFLICT reasons (§11).
Replay
What to do with a command whose key matches a stored record (§7.3).
Stream
An event stream (§7.4, §9.1); also the stream of RESYNC_REQUIRED.

Constants§

EVENTS_TYPE
The type of a batch envelope: a frame type, not an event type (§9.2).
MAX_JSON_INTEGER
Largest integer a JSON number may carry here (2^53 − 1, §2).
RESPONSE_TYPE
The type of every response envelope.

Functions§

check_version
Checks an inbound envelope’s v against the connection’s negotiated version.
command_limit
The size limit of a command envelope of type kind (§12): MAX_COMMAND, except community.create and community.descriptor.publish, which may use the whole max_frame.
is_mutating
Whether a command type is mutating, hence idempotent and recorded (§7.3): every command except session.hello, *.get, *.list, message.history, audit.list, member.bans, membership.pending, invite.uses, community.rotations, attachment.download, voice.signal, voice.keys, sync.* and signal.*. voice.signal and voice.keys change nothing at the host: they are relayed live, and a retry is relayed again.
is_recorded
Whether response is stored in the idempotency record (§7.3); see ResponseEnvelope::is_recorded.
negotiate
Chooses the highest version in both ranges (session.hello, §6.2).
parse_command
Parses a whole or reassembled command envelope text.
replay
Compares a retried command with the stored record for its key.