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

[question] byte buffer manipulation with mruby #6025

Open
mdorier opened this issue Jun 21, 2023 · 1 comment
Open

[question] byte buffer manipulation with mruby #6025

mdorier opened this issue Jun 21, 2023 · 1 comment

Comments

@mdorier
Copy link

mdorier commented Jun 21, 2023

I'm looking at mruby as a candidate scripting language for an embedded C application. The application that would use it would provided a raw byte buffer allocated outside the script and that the script should populate (e.g. by serializing various data types into it, or writing an ASCII string in it, etc.).

My question is: does mruby provide a gem with a class for such a use-case? (I'm thinking something similar to memoryview in Python or ArrayBuffer in Javascript)

@matz
Copy link
Member

matz commented Jul 4, 2023

Currently, we don't have such a gem. We often use strings as byte buffers. In that case, we first allocate a string to be a buffer in Ruby, then manipulate it by byte accessing methods, e.g., getbyte, setbyte, byteslice, bytesplice, then export it to the external. The other scenario is copying a raw buffer in to a Ruby string, then manipulate it and copying back to the external buffer.

In any case, ArrayBuffer dedicated to this purpose is more convenient, so I will consider making a gem for this use-case, in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants