Module: Fraggle::Protocol
- Included in:
- Client
- Defined in:
- lib/fraggle/protocol.rb
Instance Attribute Summary collapse
-
#last_received ⇒ Object
readonly
Returns the value of attribute last_received.
Instance Method Summary collapse
- #receive_data(data) ⇒ Object
-
#receive_response(res) ⇒ Object
The default receive_response.
- #send_data(data) ⇒ Object
- #send_request(req) ⇒ Object
Instance Attribute Details
#last_received ⇒ Object (readonly)
Returns the value of attribute last_received.
7 8 9 |
# File 'lib/fraggle/protocol.rb', line 7 def last_received @last_received end |
Instance Method Details
#receive_data(data) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fraggle/protocol.rb', line 9 def receive_data(data) @last_received = Time.now (@buf ||= "") << data while @buf.length > 0 if @len && @buf.length >= @len bytes = @buf.slice!(0, @len) @len = nil res = Response.decode(bytes) receive_response(res) elsif @buf.length >= 4 bytes = @buf.slice!(0, 4) @len = bytes.unpack("N")[0] else break end end end |
#receive_response(res) ⇒ Object
The default receive_response
30 31 32 |
# File 'lib/fraggle/protocol.rb', line 30 def receive_response(res) p res end |
#send_data(data) ⇒ Object
41 42 43 |
# File 'lib/fraggle/protocol.rb', line 41 def send_data(data) super(data) end |
#send_request(req) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/fraggle/protocol.rb', line 34 def send_request(req) data = req.encode head = [data.length].pack("N") send_data("#{head}#{data}") end |