End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
IO::Buffer.size_of
size_of(data_type) → byte size
size_of(array of data_type) → byte size
io_buffer.c
View on GitHub ↗
static VALUE
io_buffer_size_of(VALUE klass, VALUE data_type)
{
if (RB_TYPE_P(data_type, T_ARRAY)) {
size_t total = 0;
for (long i = 0; i < RARRAY_LEN(data_type); i++) {
total += io_buffer_data_type_size(RB_SYM2ID(RARRAY_AREF(data_type, i)));
}
return SIZET2NUM(total);
} else {
return SIZET2NUM(io_buffer_data_type_size(RB_SYM2ID(data_type)));
}
}
Returns the size of the given data type(s) in bytes.
Example:
Example
IO::Buffer.size_of(:u32) # => 4 IO::Buffer.size_of([:u32, :u32]) # => 8