Class: HTTPX::Buffer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/httpx/buffer.rb

Overview

Internal class to abstract a string buffer, by wrapping a string and providing the minimum possible API and functionality required.

buffer = Buffer.new(640)
buffer.full? #=> false
buffer << "aa"
buffer.capacity #=> 638

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(limit) ⇒ Buffer

Returns a new instance of Buffer.



33
34
35
36
# File 'lib/httpx/buffer.rb', line 33

def initialize(limit)
  @buffer = "".b
  @limit = limit
end

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



31
32
33
# File 'lib/httpx/buffer.rb', line 31

def limit
  @limit
end

Instance Method Details

#capacityObject



42
43
44
# File 'lib/httpx/buffer.rb', line 42

def capacity
  @limit - @buffer.bytesize
end

#full?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/httpx/buffer.rb', line 38

def full?
  @buffer.bytesize >= @limit
end

#shift!(fin) ⇒ Object



46
47
48
# File 'lib/httpx/buffer.rb', line 46

def shift!(fin)
  @buffer = @buffer.byteslice(fin..-1) || "".b
end