0.0
No commit activity in last 3 years
No release in over 3 years
The gem to operate low level I/O data buffer.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

buffer

The gem to operate low level I/O data buffer

Build Status

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