Class: HTTP2::Buffer
- Inherits:
-
String
- Object
- String
- HTTP2::Buffer
- Defined in:
- lib/http/2/buffer.rb
Overview
Simple binary buffer backed by string.
Instance Method Summary collapse
-
#getbyte ⇒ Object
Emulate StringIO#getbyte: slice first byte from buffer.
-
#initialize ⇒ 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 ⇒ Object
Alias getbyte to readbyte.
Constructor Details
#initialize ⇒ Buffer
Forces binary encoding on the string
9 10 11 |
# File 'lib/http/2/buffer.rb', line 9 def initialize(*) super.force_encoding(Encoding::BINARY) end |
Instance Method Details
#getbyte ⇒ Object
Emulate StringIO#getbyte: slice first byte from buffer.
24 25 26 |
# File 'lib/http/2/buffer.rb', line 24 def getbyte read(1).ord end |
#read(n) ⇒ Object
Emulate StringIO#read: slice first n bytes from the buffer.
16 17 18 |
# File 'lib/http/2/buffer.rb', line 16 def read(n) Buffer.new(slice!(0, n)) end |
#read_uint32 ⇒ Integer
Slice unsigned 32-bit integer from buffer.
30 31 32 |
# File 'lib/http/2/buffer.rb', line 30 def read_uint32 read(4).unpack(UINT32).first end |
#readbyte ⇒ Object
Alias getbyte to readbyte
21 |
# File 'lib/http/2/buffer.rb', line 21 alias_method :readbyte, :getbyte |