GamendWeb.EventCodec (gamend_web v1.0.1215)

Copy Markdown View Source

Encodes realtime channel event payloads as protobuf for sockets connected with ?format=protobuf (see proto/gamend_realtime.proto, the wire contract shared with all clients).

encode/3 is the single source of truth for the event → message mapping. Events without a mapping return :json and are delivered as regular JSON, so protobuf coverage can grow event by event without breaking clients.

Transforms relative to the JSON payloads (documented in the proto file): timestamps become unix milliseconds, arbitrary JSON values (metadata, KV data) become JSON-encoded bytes.

Summary

Functions

Encodes payload for event pushed on topic.

Functions

encode(topic, event, payload)

@spec encode(String.t(), String.t(), map()) :: {:ok, iodata()} | :json

Encodes payload for event pushed on topic.

Returns {:ok, iodata} or :json when the event has no protobuf mapping.