class HTTP2::Buffer

Binary buffer wraps String.

Constants

UINT32

Public Class Methods

new(str = '') click to toggle source

Forces binary encoding on the string

# File lib/http/2/buffer.rb, line 17
def initialize(str = '')
  str = str.dup if str.frozen?
  @buffer = str.force_encoding(Encoding::BINARY)
end

Public Instance Methods

+(other) click to toggle source
# File lib/http/2/buffer.rb, line 50
def +(other)
  @buffer += other
end
==(other) click to toggle source
# File lib/http/2/buffer.rb, line 46
def ==(other)
  @buffer == other
end
force_encoding(*args) click to toggle source
# File lib/http/2/buffer.rb, line 42
def force_encoding(*args)
  @buffer = @buffer.force_encoding(*args)
end
getbyte() click to toggle source

Emulate StringIO#getbyte: slice first byte from buffer.

# File lib/http/2/buffer.rb, line 30
def getbyte
  read(1).ord
end
read(n) click to toggle source

Emulate StringIO#read: slice first n bytes from the buffer.

@param n [Integer] number of bytes to slice from the buffer

# File lib/http/2/buffer.rb, line 25
def read(n)
  Buffer.new(@buffer.slice!(0, n))
end
read_uint32() click to toggle source

Slice unsigned 32-bit integer from buffer. @return [Integer]

# File lib/http/2/buffer.rb, line 61
def read_uint32
  read(4).unpack(UINT32).first
end
readbyte(n) click to toggle source

Emulate String#getbyte: return nth byte from buffer.

# File lib/http/2/buffer.rb, line 55
def readbyte(n)
  @buffer[n].ord
end
slice(*args) click to toggle source
# File lib/http/2/buffer.rb, line 38
def slice(*args)
  Buffer.new(@buffer.slice(*args))
end
slice!(*args) click to toggle source
# File lib/http/2/buffer.rb, line 34
def slice!(*args)
  Buffer.new(@buffer.slice!(*args))
end