def METHOD_NAME(self, array, type_):
    # TODO max array size is 64MiB (67108864 bytes)
    written = self.align(4)
    # length placeholder
    offset = len(self.buffer)
    written += self.write_uint32(0)
    child_type = type_.children[0]
    if child_type.token in "xtd{(":
        # the first alignment is not included in array size
        written += self.align(8)
    array_len = 0
    if child_type.token == "{":
        for key, value in array.items():
            array_len += self.write_dict_entry([key, value], child_type)
    elif child_type.token == "y":
        array_len = len(array)
        self.buffer.extend(array)
    else:
        for value in array:
            array_len += self.write_single(child_type, value)
    array_len_packed = pack("<I", array_len)
    for i in range(offset, offset + 4):
        self.buffer[i] = array_len_packed[i - offset]
    return written + array_len