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(data = '') ⇒ 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(data = '') ⇒ Buffer
Forces binary encoding on the string
12 13 14 |
# File 'lib/http/2/buffer.rb', line 12 def initialize(data = '') super(data.force_encoding(BINARY)) end |
Instance Method Details
#getbyte ⇒ Object
Emulate StringIO#getbyte: slice first byte from buffer.
27 28 29 |
# File 'lib/http/2/buffer.rb', line 27 def getbyte read(1).ord end |
#read(n) ⇒ Object
Emulate StringIO#read: slice first n bytes from the buffer.
19 20 21 |
# File 'lib/http/2/buffer.rb', line 19 def read(n) Buffer.new(slice!(0,n)) end |
#read_uint32 ⇒ Integer
Slice unsigned 32-bit integer from buffer.
33 34 35 |
# File 'lib/http/2/buffer.rb', line 33 def read_uint32 read(4).unpack(UINT32).first end |
#readbyte ⇒ Object
Alias getbyte to readbyte
24 |
# File 'lib/http/2/buffer.rb', line 24 alias :readbyte :getbyte |