Class: HTTPX::Buffer

Inherits:
Object
  • 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? #=> false
buffer << "aa"
buffer.capacity #=> 638

Direct Known Subclasses

Plugins::StreamBidi::BidiBuffer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(limit) ⇒ Buffer

Returns a new instance of Buffer.

Parameters:

  • limit (Integer)


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

#limitInteger (readonly)

Returns the value of attribute limit.

Returns:

  • (Integer)


29
30
31
# File 'lib/httpx/buffer.rb', line 29

def limit
  @limit
end

Instance Method Details

#<<(chunk) ⇒ String

delegated

Parameters:

  • data (String)

Returns:

  • (String)


17
18
19
# File 'sig/buffer.rbs', line 17

def <<(chunk)
  @buffer.append_as_bytes(chunk)
end

#bytesizeInteger, Float

Returns:

  • (Integer, Float)


19
# File 'sig/buffer.rbs', line 19

def bytesize: () -> (Integer | Float)

#capacityInteger

Returns:

  • (Integer)


53
54
55
# File 'lib/httpx/buffer.rb', line 53

def capacity
  @limit - @buffer.bytesize
end

#clearvoid

This method returns an undefined value.



20
# File 'sig/buffer.rbs', line 20

def clear: () -> void

#empty?Boolean

Returns:

  • (Boolean)


18
# File 'sig/buffer.rbs', line 18

def empty?: () -> bool

#full?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/httpx/buffer.rb', line 49

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

#replacevoid

This method returns an undefined value.

Parameters:

  • (string)


21
# File 'sig/buffer.rbs', line 21

def replace: (string) -> void

#shift!(fin) ⇒ void

This method returns an undefined value.

Parameters:

  • (Integer)


57
58
59
# File 'lib/httpx/buffer.rb', line 57

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