encode(msg) -> SLIP-encoded message.

    Encodes a message (a byte sequence) into a
    SLIP-encoded packet.

    :param bytes msg: The message that must be encoded
    :return: The SLIP-encoded message
    :rtype: bytes

def encode(msg):
    """encode(msg) -> SLIP-encoded message.

    Encodes a message (a byte sequence) into a
    SLIP-encoded packet.

    :param bytes msg: The message that must be encoded
    :return: The SLIP-encoded message
    :rtype: bytes
    """
    msg = bytes(msg)
    return END + msg.replace(ESC, ESC + ESC_ESC).replace(END, ESC + ESC_END) + END