flush() -> List of decoded messages.

        Decodes the packets in the internal buffer.
        This enables the continuation of the processing
        of received packets after a :exc:`ProtocolError`
        has been handled.

        :return: A (possibly empty) list of decoded messages from the buffered packets.
        :rtype: list(bytes)
        :raises ProtocolError: An invalid byte sequence has been detected.

def flush(self):
        """flush() -> List of decoded messages.

        Decodes the packets in the internal buffer.
        This enables the continuation of the processing
        of received packets after a :exc:`ProtocolError`
        has been handled.

        :return: A (possibly empty) list of decoded messages from the buffered packets.
        :rtype: list(bytes)
        :raises ProtocolError: An invalid byte sequence has been detected.
        """
        messages = []
        while self._packets:
            p = self._packets.popleft()
            try:
                msg = decode(p)
            except ProtocolError:
                # Add any already decoded messages to the exception
                self._messages = messages
                raise
            messages.append(msg)
        return messages