buffer
The gem to operate low level I/O data buffer
Example
gem install 'data-buffer'
require 'buffer'
buf = Buffer.new(1024) # Create char* buffer with size of 1024
buf.clear # memset 0 to buffer size
buf.size # return buffer size
buf.to_s # convert to string.
buf.bytes # convert to char byte array
buf.memset(1, 4) # set first 4 bytes to 1
buf.resize(2048) # realloc the buffer to 2048
buf = Buffer.from('Hello World') # Create char* from existing string
buf = Buffer.from([1, 2, 3, 244]) # Create char* from existing char array
buf.data # Get raw data struct
# struct buffer_data {
# size_t buffer_size;
# char* buffer;
# };
#
# buffer_data* data = (buffer_data*) ((struct RData *)obj)->data;
# Both `clone` and `dup` could copy the buffer
buf2 = buf.clone
buf3 = buf.dup
buf2.memcmp(buf3) # compare the common parts
buf2.memcmp(buf3, 2) # compare the first 2 bytes
buf2 <=> buf3 # alias of memcmp