Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | hidemat |
What should I place in *p_dst
if all I have is the p_length
?
uint64_t FileAccess::get_buffer(uint8_t *p_dst, uint64_t p_length)
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | hidemat |
What should I place in *p_dst
if all I have is the p_length
?
uint64_t FileAccess::get_buffer(uint8_t *p_dst, uint64_t p_length)
Reply From: | skysphr |
p_dst
is a pointer to the buffer in which the data in the file is to be stored as bytes. Create an empty buffer of length p_length
and pass it to the function.
I see I think I get it but I’m no sure. I’m trying to replace this series of statements that were written for a GDNative plugin
. GDNative plugins
have access to File::get_buffer
which only requires a p_length
. Here is the original code:
/* Read and populate the data */
PoolByteArray arr = p->file->get_buffer(len);
PoolByteArray::Read r = arr.read();
memcpy(zBuf, r.ptr(), len);
Here is what I did, but I’m pretty sure it’s wrong:
/* Read and populate the data */
PoolVector<uint8_t> arr;
arr.resize(len);
PoolVector<uint8_t>::Write arr_w = arr.write();
p->file->get_buffer(arr_w.ptr(), len);
PoolByteArray::Read r = arr.read();
memcpy(zBuf, r.ptr(), iAmt);
What do you think?
[EDIT]
Aaaaactually there seems to be _File
class in core_bind.h
, which I think is the class that is exposed to GDNative
and GDscript
right?
hidemat | 2022-02-21 14:06