Class: HTTP2::Buffer
- Inherits:
-
Object
- Object
- HTTP2::Buffer
- Extended by:
- Forwardable
- Defined in:
- lib/http/2/buffer.rb
Overview
Binary buffer wraps String.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object
- #force_encoding(*args) ⇒ Object
-
#getbyte ⇒ Object
Emulate StringIO#getbyte: slice first byte from buffer.
-
#initialize(str = '') ⇒ Buffer
constructor
Forces binary encoding on the string.
-
#read(n) ⇒ Object
Emulate StringIO#read: slice first n bytes from the buffer.
-
#read_uint32 ⇒ Integer
Slice unsigned 32-bit integer from buffer.
-
#readbyte(n) ⇒ Object
Emulate String#getbyte: return nth byte from buffer.
- #slice(*args) ⇒ Object
- #slice!(*args) ⇒ Object
Constructor Details
#initialize(str = '') ⇒ Buffer
Forces binary encoding on the string
17 18 19 20 |
# File 'lib/http/2/buffer.rb', line 17 def initialize(str = '') str = str.dup if str.frozen? @buffer = str.force_encoding(Encoding::BINARY) end |
Instance Method Details
#+(other) ⇒ Object
50 51 52 |
# File 'lib/http/2/buffer.rb', line 50 def +(other) @buffer += other end |
#==(other) ⇒ Object
46 47 48 |
# File 'lib/http/2/buffer.rb', line 46 def ==(other) @buffer == other end |
#force_encoding(*args) ⇒ Object
42 43 44 |
# File 'lib/http/2/buffer.rb', line 42 def force_encoding(*args) @buffer = @buffer.force_encoding(*args) end |
#getbyte ⇒ Object
Emulate StringIO#getbyte: slice first byte from buffer.
30 31 32 |
# File 'lib/http/2/buffer.rb', line 30 def getbyte read(1).ord end |
#read(n) ⇒ Object
Emulate StringIO#read: slice first n bytes from the buffer.
25 26 27 |
# File 'lib/http/2/buffer.rb', line 25 def read(n) Buffer.new(@buffer.slice!(0, n)) end |
#read_uint32 ⇒ Integer
Slice unsigned 32-bit integer from buffer.
61 62 63 |
# File 'lib/http/2/buffer.rb', line 61 def read_uint32 read(4).unpack(UINT32).first end |
#readbyte(n) ⇒ Object
Emulate String#getbyte: return nth byte from buffer.
55 56 57 |
# File 'lib/http/2/buffer.rb', line 55 def readbyte(n) @buffer[n].ord end |