protected function parsePayload($response)
    {
        if ($response instanceof ResponseInterface) {
            return $response;
        }

        // TODO: I don't exactly like how we are handling this condition.
        if ($this->closing) {
            return null;
        }

        switch ($response[0]) {
            case self::SUBSCRIBE:
            case self::UNSUBSCRIBE:
            case self::PSUBSCRIBE:
            case self::PUNSUBSCRIBE:
                if ($response[2] === 0) {
                    $this->closing = true;
                }

                return null;

            case self::MESSAGE:
                return (object) [
                    'kind'    => $response[0],
                    'channel' => $response[1],
                    'payload' => $response[2],
                ];

            case self::PMESSAGE:
                return (object) [
                    'kind'    => $response[0],
                    'pattern' => $response[1],
                    'channel' => $response[2],
                    'payload' => $response[3],
                ];

            case self::PONG:
                return (object) [
                    'kind'    => $response[0],
                    'payload' => $response[1],
                ];

            default:
                throw new RuntimeException(
                    "Received an unknown message type {$response[0]} inside of a pubsub context"
                );
        }
    }