Class: ByteBuffer
- Inherits:
-
Object
- Object
- ByteBuffer
- Defined in:
- lib/bytebuffer.rb,
lib/bytebuffer/version.rb
Overview
A ByteBuffer provides functions for interacting with buffered IO data. This gem wraps the bytebuffer rust crate located at github.com/terahlunah/bytebuffer using FFI.
Constant Summary collapse
- VERSION =
Returns version number of the library.
'0.1.0'
Instance Attribute Summary collapse
-
#VERSION ⇒ Integer
readonly
Version number of the library.
Instance Method Summary collapse
-
#clear ⇒ Object
Clear all bytes from the ByteBuffer.
-
#free ⇒ Object
(also: #drop, #destroy)
Frees the memory allocated for this ByteBuffer.
-
#get_read_position ⇒ Integer
Gets the read cursor’s current position.
-
#get_write_position ⇒ Integer
Gets the write cursor’s current position.
-
#initialize ⇒ ByteBuffer
constructor
Constructs a new ByteBuffer.
-
#is_empty? ⇒ Boolean
Is the ByteBuffer empty?.
-
#length ⇒ Integer
Returns the length of the ByteBuffer.
-
#read_bit ⇒ Boolean
Read a single bit from the ByteBuffer as a boolean value.
-
#read_bits(amount) ⇒ Integer
Read a series of bits from the ByteBuffer as a single unsigned 64-bit integer.
-
#read_f32 ⇒ Float
Read a single 32-bit signed float from the ByteBuffer.
-
#read_f64 ⇒ Float
Read a single 32-bit signed float from the ByteBuffer.
-
#read_i16 ⇒ Integer
Read a single 16-bit signed integer from the ByteBuffer.
-
#read_i32 ⇒ Integer
Read a single 32-bit signed integer from the ByteBuffer.
-
#read_i64 ⇒ Integer
Read a single 64-bit signed integer from the ByteBuffer.
-
#read_i8 ⇒ Integer
Read a single 8-bit signed integer from the ByteBuffer.
-
#read_u16 ⇒ Integer
Read a single 16-bit unsigned integer from the ByteBuffer.
-
#read_u32 ⇒ Integer
Read a single 32-bit unsigned integer from the ByteBuffer.
-
#read_u64 ⇒ Integer
Read a single 64-bit unsigned integer from the ByteBuffer.
-
#read_u8 ⇒ Integer
Read a single 8-bit unsigned integer from the ByteBuffer.
-
#reset_bits_cursor ⇒ Object
Resets the bit cursor position.
-
#reset_cursors ⇒ Object
Resets the read and write cursor positions.
-
#resize(new_size) ⇒ Object
Resizes the ByteBuffer to the desired length.
-
#set_read_position(position) ⇒ Object
Set the read cursor to the desired position.
-
#set_write_position(position) ⇒ Object
Set the write cursor to the desired position.
-
#write_bit(value) ⇒ Object
Write a boolean value as a single bit to the ByteBuffer.
-
#write_bits(value, amount) ⇒ Object
Write a numeric value as a series of bits in the ByteBuffer.
-
#write_f32(value) ⇒ Object
Write a float value as a 32-bit signed float in the ByteBuffer.
-
#write_f64(value) ⇒ Object
Write a float value as a 64-bit signed float in the ByteBuffer.
-
#write_i16(value) ⇒ Object
Write a numeric value as a 16-bit signed integer in the ByteBuffer.
-
#write_i32(value) ⇒ Object
Write a numeric value as a 32-bit signed integer in the ByteBuffer.
-
#write_i64(value) ⇒ Object
Write a numeric value as a 64-bit signed integer in the ByteBuffer.
-
#write_i8(value) ⇒ Object
Write a numeric value as a 8-bit signed integer in the ByteBuffer.
-
#write_u16(value) ⇒ Object
Write a numeric value as a 16-bit unsigned integer in the ByteBuffer.
-
#write_u32(value) ⇒ Object
Write a numeric value as a 32-bit unsigned integer in the ByteBuffer.
-
#write_u64(value) ⇒ Object
Write a numeric value as a 64-bit unsigned integer in the ByteBuffer.
-
#write_u8(value) ⇒ Object
Write a numeric value as a 8-bit unsigned integer in the ByteBuffer.
Constructor Details
#initialize ⇒ ByteBuffer
Constructs a new ByteBuffer.
62 |
# File 'lib/bytebuffer.rb', line 62 def initialize; @ptr = ByteBufferExtension.new; end |
Instance Attribute Details
#VERSION ⇒ Integer (readonly)
Returns version number of the library.
4 |
# File 'lib/bytebuffer/version.rb', line 4 VERSION = '0.1.0' |
Instance Method Details
#clear ⇒ Object
Clear all bytes from the ByteBuffer.
75 |
# File 'lib/bytebuffer.rb', line 75 def clear; ByteBufferExtension.clear(@ptr); end |
#free ⇒ Object Also known as: drop, destroy
This function will invoke the drop() macro in rust, passing in the pointer for the ByteBuffer. After the call is made, the pointer is set to nil.
Frees the memory allocated for this ByteBuffer.
94 95 96 97 |
# File 'lib/bytebuffer.rb', line 94 def free ByteBufferExtension.drop(@ptr) @ptr = nil # :gottem: end |
#get_read_position ⇒ Integer
Gets the read cursor’s current position.
113 |
# File 'lib/bytebuffer.rb', line 113 def get_read_position; ByteBufferExtension.get_read_position(@ptr); end |
#get_write_position ⇒ Integer
Gets the write cursor’s current position.
109 |
# File 'lib/bytebuffer.rb', line 109 def get_write_position; ByteBufferExtension.get_write_position(@ptr); end |
#is_empty? ⇒ Boolean
Is the ByteBuffer empty?
79 |
# File 'lib/bytebuffer.rb', line 79 def is_empty?; ByteBufferExtension.is_empty?(@ptr); end |
#length ⇒ Integer
Returns the length of the ByteBuffer.
66 |
# File 'lib/bytebuffer.rb', line 66 def length; ByteBufferExtension.length(@ptr); end |
#read_bit ⇒ Boolean
Read a single bit from the ByteBuffer as a boolean value.
168 |
# File 'lib/bytebuffer.rb', line 168 def read_bit; ByteBufferExtension.read_bit(@ptr); end |
#read_bits(amount) ⇒ Integer
Read a series of bits from the ByteBuffer as a single unsigned 64-bit integer.
172 |
# File 'lib/bytebuffer.rb', line 172 def read_bits(amount); ByteBufferExtension.read_bits(@ptr, amount); end |
#read_f32 ⇒ Float
Float values read from this buffer are accurate to the millionth decimal place.
Read a single 32-bit signed float from the ByteBuffer.
209 |
# File 'lib/bytebuffer.rb', line 209 def read_f32; ByteBufferExtension.read_f32(@ptr); end |
#read_f64 ⇒ Float
Float values read from this buffer are accurate to the millionth decimal place.
Read a single 32-bit signed float from the ByteBuffer.
214 |
# File 'lib/bytebuffer.rb', line 214 def read_f64; ByteBufferExtension.read_f64(@ptr); end |
#read_i16 ⇒ Integer
Read a single 16-bit signed integer from the ByteBuffer.
188 |
# File 'lib/bytebuffer.rb', line 188 def read_i16; ByteBufferExtension.read_i16(@ptr); end |
#read_i32 ⇒ Integer
Read a single 32-bit signed integer from the ByteBuffer.
196 |
# File 'lib/bytebuffer.rb', line 196 def read_i32; ByteBufferExtension.read_i32(@ptr); end |
#read_i64 ⇒ Integer
Read a single 64-bit signed integer from the ByteBuffer.
204 |
# File 'lib/bytebuffer.rb', line 204 def read_i64; ByteBufferExtension.read_i64(@ptr); end |
#read_i8 ⇒ Integer
Read a single 8-bit signed integer from the ByteBuffer.
180 |
# File 'lib/bytebuffer.rb', line 180 def read_i8; ByteBufferExtension.read_i8(@ptr); end |
#read_u16 ⇒ Integer
Read a single 16-bit unsigned integer from the ByteBuffer.
184 |
# File 'lib/bytebuffer.rb', line 184 def read_u16; ByteBufferExtension.read_u16(@ptr); end |
#read_u32 ⇒ Integer
Read a single 32-bit unsigned integer from the ByteBuffer.
192 |
# File 'lib/bytebuffer.rb', line 192 def read_u32; ByteBufferExtension.read_u32(@ptr); end |
#read_u64 ⇒ Integer
Read a single 64-bit unsigned integer from the ByteBuffer.
200 |
# File 'lib/bytebuffer.rb', line 200 def read_u64; ByteBufferExtension.read_u64(@ptr); end |
#read_u8 ⇒ Integer
Read a single 8-bit unsigned integer from the ByteBuffer.
176 |
# File 'lib/bytebuffer.rb', line 176 def read_u8; ByteBufferExtension.read_u8(@ptr); end |
#reset_bits_cursor ⇒ Object
Resets the bit cursor position.
72 |
# File 'lib/bytebuffer.rb', line 72 def reset_bits_cursor; ByteBufferExtension.reset_bits_cursor(@ptr); end |
#reset_cursors ⇒ Object
Resets the read and write cursor positions.
69 |
# File 'lib/bytebuffer.rb', line 69 def reset_cursors; ByteBufferExtension.reset_cursors(@ptr); end |
#resize(new_size) ⇒ Object
ByteBuffers can only increase in size. Lower or negative sizes will not work.
Resizes the ByteBuffer to the desired length.
84 85 86 87 88 89 90 |
# File 'lib/bytebuffer.rb', line 84 def resize(new_size) if new_size.negative? raise ArgumentError, "new_size must be positive" else ByteBufferExtension.resize(@ptr, new_size) end end |
#set_read_position(position) ⇒ Object
Set the read cursor to the desired position.
105 |
# File 'lib/bytebuffer.rb', line 105 def set_read_position(position); ByteBufferExtension.set_read_position(@ptr, position); end |
#set_write_position(position) ⇒ Object
Set the write cursor to the desired position.
101 |
# File 'lib/bytebuffer.rb', line 101 def set_write_position(position); ByteBufferExtension.set_write_position(@ptr, position); end |
#write_bit(value) ⇒ Object
Write a boolean value as a single bit to the ByteBuffer.
117 |
# File 'lib/bytebuffer.rb', line 117 def write_bit(value); ByteBufferExtension.write_bit(@ptr, value); end |
#write_bits(value, amount) ⇒ Object
Write a numeric value as a series of bits in the ByteBuffer.
122 |
# File 'lib/bytebuffer.rb', line 122 def write_bits(value, amount); ByteBufferExtension.write_bits(@ptr, value, amount); end |
#write_f32(value) ⇒ Object
The C value used is accurate to the nearest millionth decimal place.
Write a float value as a 32-bit signed float in the ByteBuffer.
159 |
# File 'lib/bytebuffer.rb', line 159 def write_f32(value); ByteBufferExtension.write_f32(@ptr, value); end |
#write_f64(value) ⇒ Object
The C value used is accurate to the nearest millionth decimal place.
Write a float value as a 64-bit signed float in the ByteBuffer.
164 |
# File 'lib/bytebuffer.rb', line 164 def write_f64(value); ByteBufferExtension.write_f64(@ptr, value); end |
#write_i16(value) ⇒ Object
Write a numeric value as a 16-bit signed integer in the ByteBuffer.
138 |
# File 'lib/bytebuffer.rb', line 138 def write_i16(value); ByteBufferExtension.write_i16(@ptr, value); end |
#write_i32(value) ⇒ Object
Write a numeric value as a 32-bit signed integer in the ByteBuffer.
146 |
# File 'lib/bytebuffer.rb', line 146 def write_i32(value); ByteBufferExtension.write_i32(@ptr, value); end |
#write_i64(value) ⇒ Object
Write a numeric value as a 64-bit signed integer in the ByteBuffer.
154 |
# File 'lib/bytebuffer.rb', line 154 def write_i64(value); ByteBufferExtension.write_i64(@ptr, value); end |
#write_i8(value) ⇒ Object
Write a numeric value as a 8-bit signed integer in the ByteBuffer.
130 |
# File 'lib/bytebuffer.rb', line 130 def write_i8(value); ByteBufferExtension.write_i8(@ptr, value); end |
#write_u16(value) ⇒ Object
Write a numeric value as a 16-bit unsigned integer in the ByteBuffer.
134 |
# File 'lib/bytebuffer.rb', line 134 def write_u16(value); ByteBufferExtension.write_u16(@ptr, value); end |
#write_u32(value) ⇒ Object
Write a numeric value as a 32-bit unsigned integer in the ByteBuffer.
142 |
# File 'lib/bytebuffer.rb', line 142 def write_u32(value); ByteBufferExtension.write_u32(@ptr, value); end |
#write_u64(value) ⇒ Object
Write a numeric value as a 64-bit unsigned integer in the ByteBuffer.
150 |
# File 'lib/bytebuffer.rb', line 150 def write_u64(value); ByteBufferExtension.write_u64(@ptr, value); end |
#write_u8(value) ⇒ Object
Write a numeric value as a 8-bit unsigned integer in the ByteBuffer.
126 |
# File 'lib/bytebuffer.rb', line 126 def write_u8(value); ByteBufferExtension.write_u8(@ptr, value); end |