def METHOD_NAME(data: ScopeSession, scope: Scope | None = None) -> bytes:
    """Serialize data into bytes for storage in the backend.
    Args:
        data: Session data of the current scope.
        scope: A scope, if applicable, from which to extract a serializer.
    Notes:
        - The serializer will be extracted from ``scope`` or fall back to
            :func:`default_serializer <.serialization.default_serializer>`
    Returns:
        ``data`` serialized as bytes.
    """
    serializer = get_serializer_from_scope(scope) if scope else None
    return encode_json(data, serializer)