Class: HTTP2Next::Buffer
- Inherits:
-
Object
- Object
- HTTP2Next::Buffer
- Extended by:
- Forwardable
- Defined in:
- lib/http/2/next/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 = "".b) ⇒ 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 = "".b) ⇒ Buffer
Forces binary encoding on the string
19 20 21 22 |
# File 'lib/http/2/next/buffer.rb', line 19 def initialize(str = "".b) str = str.dup if str.frozen? @buffer = str.force_encoding(Encoding::BINARY) end |
Instance Method Details
#+(other) ⇒ Object
52 53 54 |
# File 'lib/http/2/next/buffer.rb', line 52 def +(other) @buffer += other end |
#==(other) ⇒ Object
48 49 50 |
# File 'lib/http/2/next/buffer.rb', line 48 def ==(other) @buffer == other end |
#force_encoding(*args) ⇒ Object
44 45 46 |
# File 'lib/http/2/next/buffer.rb', line 44 def force_encoding(*args) @buffer = @buffer.force_encoding(*args) end |
#getbyte ⇒ Object
Emulate StringIO#getbyte: slice first byte from buffer.
32 33 34 |
# File 'lib/http/2/next/buffer.rb', line 32 def getbyte read(1).ord end |
#read(n) ⇒ Object
Emulate StringIO#read: slice first n bytes from the buffer.
27 28 29 |
# File 'lib/http/2/next/buffer.rb', line 27 def read(n) Buffer.new(@buffer.slice!(0, n)) end |
#read_uint32 ⇒ Integer
Slice unsigned 32-bit integer from buffer.
63 64 65 |
# File 'lib/http/2/next/buffer.rb', line 63 def read_uint32 read(4).unpack(UINT32).first end |
#readbyte(n) ⇒ Object
Emulate String#getbyte: return nth byte from buffer.
57 58 59 |
# File 'lib/http/2/next/buffer.rb', line 57 def readbyte(n) @buffer[n].ord end |