Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing contents of std::vector to a QuickJS function #7

Open
juanBerger opened this issue Mar 3, 2023 · 1 comment
Open

Passing contents of std::vector to a QuickJS function #7

juanBerger opened this issue Mar 3, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@juanBerger
Copy link

I'm missing something basic I think.
I have a file read into a vector:

std::vector<uint8_t>fileBuffer((std::istreambuf_iterator<char>(file)), (std::istreambuf_iterator<char>()));

I want to load it into a js Uint8Array. The only way that works for me so far is one byte at a time:

for (int i = 0; i < fileBuffer.size(); ++i){
  uint8_t byte = fileBuffer[i];
  jsContext.invoke("putByte", byte);
}

This is pretty slow. I can pass a pointer, but not sure how to de reference that on the js side.
What's the best way to do this?
Many Thanks!

@juanBerger juanBerger changed the title Passing a std::vector to a QuickJS function Passing contents of std::vector to a QuickJS function Mar 3, 2023
@julianstorer
Copy link
Collaborator

Good question - I don't really know how quickjs handles IntArrays, it'd take a bit of research to figure out an efficient way to get the data in and out..

@julianstorer julianstorer added the enhancement New feature or request label Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants