def _ihexline(address, buffer, end=False, record_type=0):
    """internal use: generate a line with intel hex encoded data"""
    out = []
    if end:
        record_type = 1
    out.append(b':%02X%04X%02X' % (len(buffer), address & 65535, record_type))
    sum = len(buffer) + (address >> 8 & 255) + (address & 255) + (record_type &
        255)
    for b in bytearray(buffer):
        out.append(b'%02X' % (b & 255))
        sum += b & 255
    out.append(b'%02X\r\n' % (-sum & 255))
    return b''.join(out)
