PhoenixWebTransport.Lanes (phoenix_wtransport v0.1.0)

Copy Markdown View Source

Lane bookkeeping shared between LaneSerializer, SessionEngine, and Quic.Session.

A push from the Phoenix socket is one of:

  • {:text | :binary, iodata} (or list of pushes) routed to control lane 0

  • A lane container ("L" or causal-barrier "B") produced by PhoenixWebTransport.LaneSerializer
  • {:datagram, iodata} or {:datagram, :text | :binary, iodata} for opt-in RFC 9297 unreliable datagrams

Summary

Functions

The control lane id.

Decodes a typed datagram payload.

Wraps a control lane JSON payload with a causal barrier wait map %{slot => expected_seq} as ["__wt_barrier", wait_map, original_json].

Encodes a typed datagram payload with a 1-byte type tag (0 text, 1 binary).

Turns a single socket push into normalized lane frames.

Turns one push or a list of pushes into normalized lane frames.

Maps a lane onto one of max_lanes stream slots. Lane 0 keeps its own stream; component lanes share the remaining slots round-robin.

Shortest message first on the RFC 9218 urgency scale (0 most urgent, 7 least; erlang_quic reserves 0 for its own control streams).

Types

lane_frame()

@type lane_frame() ::
  {non_neg_integer(), {:text | :binary, binary()}}
  | {:barrier, 0, {:text, binary()}, [pos_integer()]}
  | {:datagram, {:text | :binary, binary()}}

push()

@type push() ::
  {:text | :binary, iodata()}
  | {:datagram, iodata()}
  | {:datagram, :text | :binary, iodata()}

Functions

control()

@spec control() :: non_neg_integer()

The control lane id.

decode_datagram(payload)

@spec decode_datagram(binary()) :: {:text | :binary, binary()}

Decodes a typed datagram payload.

encode_barrier(wait_map, control_json)

@spec encode_barrier(%{optional(non_neg_integer()) => pos_integer()}, binary()) ::
  binary()

Wraps a control lane JSON payload with a causal barrier wait map %{slot => expected_seq} as ["__wt_barrier", wait_map, original_json].

encode_datagram(atom, payload)

@spec encode_datagram(:text | :binary, binary()) :: binary()

Encodes a typed datagram payload with a 1-byte type tag (0 text, 1 binary).

frames_for_push(arg)

@spec frames_for_push(push()) :: [lane_frame()]

Turns a single socket push into normalized lane frames.

frames_for_pushes(pushes)

@spec frames_for_pushes(push() | [push()]) :: [lane_frame()]

Turns one push or a list of pushes into normalized lane frames.

slot_for(lane, max)

@spec slot_for(non_neg_integer(), pos_integer()) :: non_neg_integer()

Maps a lane onto one of max_lanes stream slots. Lane 0 keeps its own stream; component lanes share the remaining slots round-robin.

urgency(size)

@spec urgency(non_neg_integer()) :: 1..7

Shortest message first on the RFC 9218 urgency scale (0 most urgent, 7 least; erlang_quic reserves 0 for its own control streams).