Class: Miu::Packet
- Inherits:
-
Object
- Object
- Miu::Packet
- Defined in:
- lib/miu/packet.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#tag ⇒ Object
Returns the value of attribute tag.
Class Method Summary collapse
Instance Method Summary collapse
- #dump ⇒ Object
-
#initialize(tag, data) ⇒ Packet
constructor
A new instance of Packet.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(tag, data) ⇒ Packet
Returns a new instance of Packet.
8 9 10 11 |
# File 'lib/miu/packet.rb', line 8 def initialize(tag, data) @tag = tag @data = data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/miu/packet.rb', line 6 def data @data end |
#tag ⇒ Object
Returns the value of attribute tag.
6 7 8 |
# File 'lib/miu/packet.rb', line 6 def tag @tag end |
Class Method Details
.load(parts) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/miu/packet.rb', line 17 def self.load(parts) tag = parts[0] data = MessagePack.unpack(parts[1]) new tag, data rescue => e raise PacketLoadError, e end |
Instance Method Details
#dump ⇒ Object
13 14 15 |
# File 'lib/miu/packet.rb', line 13 def dump [@tag.to_s, @data.to_msgpack] end |
#inspect ⇒ Object
29 30 31 32 33 34 |
# File 'lib/miu/packet.rb', line 29 def inspect inspection = [:tag, :data].map do |name| "#{name}: #{__send__(name).inspect}" end.join(', ') "#<#{self.class} #{inspection}>" end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/miu/packet.rb', line 25 def to_s "<#{tag}> #{data.to_h}" end |