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
Wasm CopyBytesToGo
does not work
#39129
Comments
You need to create Unlike other projects, we do not use the issue tracker for questions such as these. It is only used for bugs and feature proposals. I will close this issue, but please feel free to ask it in any of these forums below:
Thanks |
@agnivade thank you for replying. I have successfully resolved it in my project. My point being one can specify this example or note in the docs. It will be very helpful for others who are getting started |
I have tried adding an example here, but it was rejected at the end because it turned out to be too complicated to be an example. If you have a better way to add an example, please feel free to send a CL. |
@agnivade Thanks! This was exactly what I needed to pull a JS Uint8Array into a Go byte slice For anyone in the future: the trick is to initialize the byte-slice with the JS-land length before doing the copying, like this: array := args[0]
buf := make([]byte, array.Get("length").Int())
n := js.CopyBytesToGo(buf, array) |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Do not know
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I had a file which I fetched using the JS Fetch API. I converted the contents of the file to Uint8Array.
And passed the Uint8Array as a parameter to the globally registered golang function in my wasm file.
Now as per the https://www.godoc.org/syscall/js#CopyBytesToGo documentation spcified here. If one gives a Uint8Array to
CopyBytesToGo
function then one must get the[]byte
What did you expect to see?
I expected to see my target buffer or
[]byte
to contain the bytes from theUint8Array
passed from JS. And the count to be non zeroWhat did you see instead?
I get the count to be 0 and the type to be
object
The text was updated successfully, but these errors were encountered: