Class: ReverseTunnel::Message::Unpacker

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/reverse-tunnel/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUnpacker

Returns a new instance of Unpacker.



42
43
44
# File 'lib/reverse-tunnel/message.rb', line 42

def initialize
  @unpacker = MessagePack::Unpacker.new
end

Instance Attribute Details

#unpackerObject (readonly)

Returns the value of attribute unpacker.



40
41
42
# File 'lib/reverse-tunnel/message.rb', line 40

def unpacker
  @unpacker
end

Instance Method Details

#each(&block) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/reverse-tunnel/message.rb', line 51

def each(&block)
  unpacker.each do |data|
    type_id = data.shift
    payload = data

    Message.create(type_id).tap do |message|
      message.load(payload)

      yield message
    end
  end
end

#feed(data) ⇒ Object



46
47
48
# File 'lib/reverse-tunnel/message.rb', line 46

def feed(data)
  unpacker.feed data
end