Module: Funl::Stream

Included in:
Client, MessageSequencer
Defined in:
lib/funl/stream.rb

Overview

Mixin depends on stream_type, log, client_id, message_class.

Instance Method Summary collapse

Instance Method Details

#client_stream_for(io, type: stream_type) ⇒ Object



6
7
8
9
10
11
# File 'lib/funl/stream.rb', line 6

def client_stream_for io, type: stream_type
  ObjectStreamWrapper.new(io, type: type).tap do |stream|
    stream.write_to_outbox {{"client_id" => client_id}}
      # client_id will be nil in the case of cseq, but that's ok.
  end
end

#message_server_stream_for(io, type: stream_type) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/funl/stream.rb', line 23

def message_server_stream_for io, type: stream_type
  ObjectStreamWrapper.new(io, type: type).tap do |stream|
    stream.consume do |h|
      client_id = h["client_id"]
      stream.peer_name = "client #{client_id}"
      log.info "peer is #{stream.peer_name}"
      stream.expect message_class
    end
  end
end

#server_stream_for(io, type: stream_type) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/funl/stream.rb', line 13

def server_stream_for io, type: stream_type
  ObjectStreamWrapper.new(io, type: type).tap do |stream|
    stream.consume do |h|
      client_id = h["client_id"]
      stream.peer_name = "client #{client_id}"
      log.info "peer is #{stream.peer_name}"
    end
  end
end