Search code examples
rubybufferlibusb

ruby equivalent of a c buffer


I am working on a small script using the USB bindings for ruby.

Since this is just a wrapper around libusb, all of C++'s features are visible through the abstraction, for example when usb_bulk_read requires giving a buffer as an argument (which would just be a pointer in C).

How can I create a buffer which is 64bytes long, for the following bit of code, without having to create a string with 64 spaces in coded into the program (which I am doing ATM). I wish ruby had pointers for this!

data =  "          "; /#etc. You get the idea
handle.usb_bulk_read(1, data, 0)

Where handle is a USB::DevHandle object which has already been opened.


Solution

  • Simple answer that probably avoids the core issue:

    data = ' ' * 64