Class: Warden::Protocol::Buffer

Inherits:
Object
  • Object
show all
Defined in:
lib/warden/protocol/buffer.rb

Constant Summary collapse

CRLF =
"\r\n"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuffer

Returns a new instance of Buffer.



24
25
26
# File 'lib/warden/protocol/buffer.rb', line 24

def initialize
  @buffer = ""
end

Class Method Details

.request_to_wire(request) ⇒ Object



10
11
12
13
14
15
# File 'lib/warden/protocol/buffer.rb', line 10

def self.request_to_wire(request)
  unless request.kind_of?(BaseRequest)
    raise ArgumentError, "Expected #kind_of? ::%s" % BaseRequest.name
  end
  payload_to_wire request.wrap.encode.to_s
end

.response_to_wire(response) ⇒ Object



17
18
19
20
21
22
# File 'lib/warden/protocol/buffer.rb', line 17

def self.response_to_wire(response)
  unless response.kind_of?(BaseResponse)
    raise ArgumentError, "Expected #kind_of? ::%s" % BaseResponse.name
  end
  payload_to_wire response.wrap.encode.to_s
end

Instance Method Details

#<<(data) ⇒ Object



28
29
30
# File 'lib/warden/protocol/buffer.rb', line 28

def <<(data)
  @buffer += data
end

#each_request(&blk) ⇒ Object



32
33
34
35
36
# File 'lib/warden/protocol/buffer.rb', line 32

def each_request(&blk)
  each do |payload|
    yield(Warden::Protocol::Message.decode(payload).request)
  end
end

#each_response(&blk) ⇒ Object



38
39
40
41
42
# File 'lib/warden/protocol/buffer.rb', line 38

def each_response(&blk)
  each do |payload|
    yield(Warden::Protocol::Message.decode(payload).response)
  end
end