garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/adr/009-application-protocol-envelope-v0.md

raw

ADR-009: Application Protocol Envelope (v0)


Metadata:


Context

Problem: Framed TCP (ADR-008) needs a versioned, extensible inner format so client and sim can evolve.

Requirements:

Decision

Every TCP frame body (ADR-008 length-delimited) is an app frame: an 8-byte header + postcard payload.

Header (crates/cartopolis_core/src/protocol.rs, all little-endian):

Body: postcard-encoded NetMessage (the rest of the frame — the transport already delimits length, so no inner length prefix). serde derives on every message; uuid::Uuid for session ids; thiserror (ProtocolError) for typed decode errors.

Handshake / gate: ClientHello { protocol_version, client_token } → ServerHelloAck { session_id, tick_hz, your_avatar_id, osm_tile_url_template } (or ServerError) before any WorldSnapshot/ClientIntent. Auth (real credential verification) is not built — client_token is an opaque placeholder for v0.

Rationale

Primary Reasoning:

  1. Evolution: Version + kind allow adding messages without new transports.
  2. Debugging: request_id links errors to client actions.
  3. Simple gate: handshake-before-scene, without a full EC-attribute schema.

Alternatives Considered:

AlternativeProsConsRejected Because
JSON-only messagesHuman-readableBandwidth + speedPoor fit for snapshots
Protobuf / gRPCSchema tooling, multi-langHeavier codegen, HTTP/2 stackDefer until multi-language clients
Bincode instead of postcardSlightly fasterLess no_std-friendly, largerPostcard is compact and deterministic enough

Consequences

Positive:

Negative:

Related