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
- #unpack1(*arg) ⇒ Object
Constructor Details
#initialize(str = "".b) ⇒ Buffer
Forces binary encoding on the string
21 22 23 24 |
# File 'lib/http/2/next/buffer.rb', line 21 def initialize(str = "".b) str = str.dup if str.frozen? @buffer = str.force_encoding(Encoding::BINARY) end |
Instance Method Details
#+(other) ⇒ Object
58 59 60 |
# File 'lib/http/2/next/buffer.rb', line 58 def +(other) @buffer += other end |
#==(other) ⇒ Object
54 55 56 |
# File 'lib/http/2/next/buffer.rb', line 54 def ==(other) @buffer == other end |
#force_encoding(*args) ⇒ Object
50 51 52 |
# File 'lib/http/2/next/buffer.rb', line 50 def force_encoding(*args) @buffer = @buffer.force_encoding(*args) end |
#getbyte ⇒ Object
Emulate StringIO#getbyte: slice first byte from buffer.
38 39 40 |
# File 'lib/http/2/next/buffer.rb', line 38 def getbyte read(1).ord end |
#read(n) ⇒ Object
Emulate StringIO#read: slice first n bytes from the buffer.
29 30 31 |
# File 'lib/http/2/next/buffer.rb', line 29 def read(n) Buffer.new(@buffer.slice!(0, n)) end |
#read_uint32 ⇒ Integer
Slice unsigned 32-bit integer from buffer.
69 70 71 |
# File 'lib/http/2/next/buffer.rb', line 69 def read_uint32 read(4).unpack1(UINT32) end |
#readbyte(n) ⇒ Object
Emulate String#getbyte: return nth byte from buffer.
63 64 65 |
# File 'lib/http/2/next/buffer.rb', line 63 def readbyte(n) @buffer[n].ord end |
#slice(*args) ⇒ Object
46 47 48 |
# File 'lib/http/2/next/buffer.rb', line 46 def slice(*args) Buffer.new(@buffer.slice(*args)) end |
#slice!(*args) ⇒ Object
42 43 44 |
# File 'lib/http/2/next/buffer.rb', line 42 def slice!(*args) Buffer.new(@buffer.slice!(*args)) end |
#unpack1(*arg) ⇒ Object
33 34 35 |
# File 'lib/http/2/next/buffer.rb', line 33 def unpack1(*arg) @buffer.unpack1(*arg) end |