Class: HTTPX::Buffer
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- _ToS, _ToStr
- Defined in:
- lib/httpx/buffer.rb,
sig/buffer.rbs
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? buffer << "aa"
buffer.capacity
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(limit) ⇒ Buffer
Returns a new instance of Buffer.
32
33
34
35
|
# File 'lib/httpx/buffer.rb', line 32
def initialize(limit)
@buffer = String.new("", encoding: Encoding::BINARY, capacity: limit)
@limit = limit
end
|
Instance Attribute Details
#limit ⇒ Integer
Returns the value of attribute limit.
29
30
31
|
# File 'lib/httpx/buffer.rb', line 29
def limit
@limit
end
|
Instance Method Details
#<<(chunk) ⇒ String
17
18
19
|
# File 'sig/buffer.rbs', line 17
def <<(chunk)
@buffer.append_as_bytes(chunk)
end
|
#bytesize ⇒ Integer, Float
19
|
# File 'sig/buffer.rbs', line 19
def bytesize: () -> (Integer | Float)
|
#capacity ⇒ Integer
58
59
60
|
# File 'lib/httpx/buffer.rb', line 58
def capacity
@limit - @buffer.bytesize
end
|
#clear ⇒ void
This method returns an undefined value.
20
|
# File 'sig/buffer.rbs', line 20
def clear: () -> void
|
#empty? ⇒ Boolean
18
|
# File 'sig/buffer.rbs', line 18
def empty?: () -> bool
|
#full? ⇒ Boolean
54
55
56
|
# File 'lib/httpx/buffer.rb', line 54
def full?
@buffer.bytesize >= @limit
end
|
#initialize_dup(other) ⇒ Object
49
50
51
52
|
# File 'lib/httpx/buffer.rb', line 49
def initialize_dup(other)
super
@buffer = other.instance_variable_get(:@buffer).dup
end
|
#replace ⇒ void
This method returns an undefined value.
21
|
# File 'sig/buffer.rbs', line 21
def replace: (string) -> void
|
#shift!(fin) ⇒ void
This method returns an undefined value.
62
63
64
|
# File 'lib/httpx/buffer.rb', line 62
def shift!(fin)
@buffer = @buffer.byteslice(fin..-1) || "".b
end
|