Skip to content

decode_frame

autogen.beta.network.transport.frames.decode_frame #

decode_frame(data)

Reconstruct a Frame from a JSON dict.

Looks up the dataclass via kind, rehydrates a nested Envelope if present, and constructs the frame. Raises ValueError on unknown kind.

Source code in autogen/beta/network/transport/frames.py
def decode_frame(data: dict[str, Any]) -> Frame:
    """Reconstruct a Frame from a JSON dict.

    Looks up the dataclass via ``kind``, rehydrates a nested
    ``Envelope`` if present, and constructs the frame. Raises
    ``ValueError`` on unknown ``kind``.
    """
    payload = dict(data)  # shallow copy — caller's dict is preserved
    kind = payload.pop("kind", None)
    if kind not in _FRAME_CLASSES:
        raise ValueError(f"unknown frame kind: {kind!r}")
    cls = _FRAME_CLASSES[kind]
    if "envelope" in payload and isinstance(payload["envelope"], dict):
        payload["envelope"] = Envelope.from_dict(payload["envelope"])
    return cls(**payload)