Reading from binary file into a dynamic array

I need to do something like this:

count: i32le
data: [dynamic]f64le
n,e := os.read_ptr( file, rawptr(&count), size_of(count))
resize(&data, count)
fmt.println("len =", len(data))

// now, read <count> f64s into the array
bytesToRead := int(count * size_of(f64le))
n,e = os.read_ptr(file, rawptr(&data), bytesToRead)
fmt.println("len =", len(data))  // ????????????

Obviously, reading into a dynamic array this way is not working. How do I go about to do this? I think, under the hood, the dynamic array is a struct width the pointer to the actual data, so I need to get the pointer to the actual data.

I’d just read the whole file, treat it as a slice.

bytes, ok := os.read_entire_file_from_filename(fname)
assert(ok)
defer delete(bytes)

count := slice.to_type(bytes, u32)
data := slice.from_ptr(cast(^f32)raw_data(bytes[size_of(count):]), int(count))

// If you really need it to be dynamic
dyn_data, err := slice.clone_into_dynamic(data, alloc)

The solution turned out to be really simple:

n,e = os.read_ptr( file, rawptr(&data[0]), bytesToRead)