Class: TgMq::InputShaper
- Inherits:
-
Object
- Object
- TgMq::InputShaper
- Defined in:
- lib/tg_mq/input_shaper.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(logger: TgMq.config.logger) ⇒ InputShaper
constructor
A new instance of InputShaper.
- #pushdata(text) ⇒ Object
Constructor Details
#initialize(logger: TgMq.config.logger) ⇒ InputShaper
Returns a new instance of InputShaper.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/tg_mq/input_shaper.rb', line 5 def initialize(logger: TgMq.config.logger) @logger = TgMq.setup_logger(logger).tagged(self.class) @frames = Hash.new do |h, | h[] = { buffer: '', frames: [] } end end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
3 4 5 |
# File 'lib/tg_mq/input_shaper.rb', line 3 def logger @logger end |
Instance Method Details
#pushdata(text) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/tg_mq/input_shaper.rb', line 16 def pushdata(text) if (frame = Frame.parse(text)) logger.info "receive frame [#{frame.id}]" frameset = @frames[frame.] data = frameset[:buffer] += frame.chunk frameset[:frames] << frame if data.end_with?(Frame::END_MSG) @frames.delete(frame.) return data[0..-5] end else logger.warn "skip [#{text.first(15)}]: not a frame" end nil end |