Class: HTTP2::Buffer

Inherits:
String
  • Object
show all
Defined in:
lib/http/2/buffer.rb

Overview

Simple binary buffer backed by string.

Instance Method Summary collapse

Constructor Details

#initializeBuffer

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

#getbyteObject

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.

Parameters:

  • n (Integer)

    number of bytes to slice from the buffer



16
17
18
# File 'lib/http/2/buffer.rb', line 16

def read(n)
  Buffer.new(slice!(0, n))
end

#read_uint32Integer

Slice unsigned 32-bit integer from buffer.

Returns:

  • (Integer)


30
31
32
# File 'lib/http/2/buffer.rb', line 30

def read_uint32
  read(4).unpack(UINT32).first
end

#readbyteObject

Alias getbyte to readbyte



21
# File 'lib/http/2/buffer.rb', line 21

alias_method :readbyte, :getbyte