End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
IO::Buffer#get_values
get_values(data_types, offset) → array
io_buffer.c
View on GitHub ↗
static VALUE
io_buffer_get_values(VALUE self, VALUE data_types, VALUE _offset)
{
size_t offset = NUM2SIZET(_offset);
const void *base;
size_t size;
rb_io_buffer_get_bytes_for_reading(self, &base, &size);
if (!RB_TYPE_P(data_types, T_ARRAY)) {
rb_raise(rb_eArgError, "Argument data_types should be an array!");
}
VALUE array = rb_ary_new_capa(RARRAY_LEN(data_types));
for (long i = 0; i < RARRAY_LEN(data_types); i++) {
VALUE type = rb_ary_entry(data_types, i);
VALUE value = rb_io_buffer_get_value(base, size, RB_SYM2ID(type), &offset);
rb_ary_push(array, value);
}
return array;
}
Similar to get_value, except that it can handle multiple data types and returns an array of values.
Example:
Example
string = [1.5, 2.5].pack('ff') IO::Buffer.for(string).get_values([:f32, :f32], 0) # => [1.5, 2.5]