receive(data) -> List of decoded messages.

        Processes :obj:`data`, which must be a bytes-like object,
        and returns a (possibly empty) list with :class:`bytes` objects,
        each containing a decoded message.
        Any non-terminated SLIP packets in :obj:`data`
        are buffered, and processed with the next call to :meth:`receive`.

        :param bytes data: The bytes-like object to be processed.
            An empty :obj:`data` parameter forces the internal
            buffer to be flushed and decoded.
        :return: A (possibly empty) list of decoded messages.
        :rtype: list(bytes)
        :raises ProtocolError: An invalid byte sequence has been detected.

def receive(self, data):
        """receive(data) -> List of decoded messages.

        Processes :obj:`data`, which must be a bytes-like object,
        and returns a (possibly empty) list with :class:`bytes` objects,
        each containing a decoded message.
        Any non-terminated SLIP packets in :obj:`data`
        are buffered, and processed with the next call to :meth:`receive`.

        :param bytes data: The bytes-like object to be processed.
            An empty :obj:`data` parameter forces the internal
            buffer to be flushed and decoded.
        :return: A (possibly empty) list of decoded messages.
        :rtype: list(bytes)
        :raises ProtocolError: An invalid byte sequence has been detected.
        """

        # Empty data indicates that the data reception is complete.
        # To force a buffer flush, an END byte is added, so that the
        # current contents of _recv_buffer will form a complete message.
        if not data:
            data = END

        self._recv_buffer += data

        # The following situations can occur:
        #
        #  1) _recv_buffer is empty or contains only END bytes --> no packets available
        #  2) _recv_buffer contains non-END bytes -->  packets are available
        #
        # Strip leading END bytes from _recv_buffer to avoid handling empty _packets.
        self._recv_buffer = self._recv_buffer.lstrip(END)
        if self._recv_buffer:
            # The _recv_buffer contains non-END bytes.
            # It is now split on sequences of one or more END bytes.
            # The trailing element from the split operation is a possibly incomplete
            # packet; this element is therefore used as the new _recv_buffer.
            # If _recv_buffer contains one or more trailing END bytes,
            # (meaning that there are no incomplete packets), then the last element,
            # and therefore the new _recv_buffer, is an empty bytes object.
            self._packets.extend(re.split(END + b'+', self._recv_buffer))
            self._recv_buffer = self._packets.pop()

        # Process the buffered packets
        return self.flush()