def encode_ipmb_msg(header, data):
    """Encode an IPMB message.

    header: IPMB header object
    data: IPMI message data as bytestring

    Returns the message as bytestring.
    """
    msg = array('B')

    msg.fromstring(header.encode())
    if data is not None:
        a = array('B')
        a.fromstring(data)
        msg.extend(a)
    msg.append(checksum(msg[3:]))
    return msg.tostring()
Encode an IPMB message.

    header: IPMB header object
    data: IPMI message data as bytestring

    Returns the message as bytestring.