import struct


def addString(array, b):
    """Add bytes to array.array("B") (uint8_t) in the format understood by readString() (prefixed by its length).
    """
    offset = len(array)
    if len(b) <= 0xfc:
        array.append(len(b))
    elif len(b) <= 0xffff:
        array.append(0xfd)
        array.frombytes(struct.pack("<H", len(b)))
    elif len(b) <= 0xffffFFFF:
        array.append(0xfe)
        array.frombytes(struct.pack("<L", len(b)))
    else:
        array.append(0xff)
        array.frombytes(struct.pack("<Q", len(b)))
    array.frombytes(b)
    return offset