Class: HTTPX::Buffer
- Inherits:
-
Object
- Object
- HTTPX::Buffer
- 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? #=> false
buffer << "aa"
buffer.capacity #=> 638
Direct Known Subclasses
Instance Attribute Summary collapse
-
#limit ⇒ Integer
readonly
Returns the value of attribute limit.
Instance Method Summary collapse
-
#<<(chunk) ⇒ String
delegated.
- #bytesize ⇒ Integer, Float
- #capacity ⇒ Integer
- #clear ⇒ void
- #empty? ⇒ Boolean
- #full? ⇒ Boolean
-
#initialize(limit) ⇒ Buffer
constructor
A new instance of Buffer.
- #replace ⇒ void
- #shift!(fin) ⇒ void
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 (readonly)
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
delegated
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
53 54 55 |
# File 'lib/httpx/buffer.rb', line 53 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
49 50 51 |
# File 'lib/httpx/buffer.rb', line 49 def full? @buffer.bytesize >= @limit 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.
57 58 59 |
# File 'lib/httpx/buffer.rb', line 57 def shift!(fin) @buffer = @buffer.byteslice(fin..-1) || "".b end |