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

#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

#getbyteObject

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.

Parameters:

  • n (Integer)

    number of bytes to slice from the buffer



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

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

#read_uint32Integer

Slice unsigned 32-bit integer from buffer.

Returns:

  • (Integer)


33
34
35
# File 'lib/http/2/buffer.rb', line 33

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

#readbyteObject

Alias getbyte to readbyte



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

alias :readbyte :getbyte