Class: ZSS::Message
- Inherits:
-
Object
- Object
- ZSS::Message
- Defined in:
- lib/zss/message.rb,
lib/zss/message/smi.rb,
lib/zss/message/message_type.rb,
lib/zss/message/message_address.rb
Defined Under Namespace
Constant Summary collapse
- PROTOCOL_VERSION =
"ZSS:0.0"
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#identity ⇒ Object
Returns the value of attribute identity.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#rid ⇒ Object
Returns the value of attribute rid.
-
#status ⇒ Object
Returns the value of attribute status.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Message
constructor
A new instance of Message.
- #is_error? ⇒ Boolean
- #req? ⇒ Boolean
- #to_frames ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Message
Returns a new instance of Message.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/zss/message.rb', line 21 def initialize(args = {}) @identity = args[:identity] @protocol = args[:protocol] || PROTOCOL_VERSION @type = args[:type] || Type::REQ @rid = args[:rid] || SecureRandom.uuid @address = args[:address] @headers = args[:headers] || {} @status = args[:status] @payload = args[:payload] end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
12 13 14 |
# File 'lib/zss/message.rb', line 12 def address @address end |
#headers ⇒ Object
Returns the value of attribute headers.
12 13 14 |
# File 'lib/zss/message.rb', line 12 def headers @headers end |
#identity ⇒ Object
Returns the value of attribute identity.
12 13 14 |
# File 'lib/zss/message.rb', line 12 def identity @identity end |
#payload ⇒ Object
Returns the value of attribute payload.
12 13 14 |
# File 'lib/zss/message.rb', line 12 def payload @payload end |
#protocol ⇒ Object
Returns the value of attribute protocol.
12 13 14 |
# File 'lib/zss/message.rb', line 12 def protocol @protocol end |
#rid ⇒ Object
Returns the value of attribute rid.
12 13 14 |
# File 'lib/zss/message.rb', line 12 def rid @rid end |
#status ⇒ Object
Returns the value of attribute status.
12 13 14 |
# File 'lib/zss/message.rb', line 12 def status @status end |
#type ⇒ Object
Returns the value of attribute type.
12 13 14 |
# File 'lib/zss/message.rb', line 12 def type @type end |
Class Method Details
.parse(frames) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/zss/message.rb', line 38 def self.parse(frames) frames.unshift(nil) if frames.length == 7 msg = Message.new( identity: frames.shift, protocol: frames.shift, type: frames.shift, rid: frames.shift, address: Address.new( MessagePack.unpack(frames.shift).with_indifferent_access ), headers: Hashie::Mash.new(MessagePack.unpack(frames.shift)), status: frames.shift.to_i, payload: MessagePack.unpack(frames.shift), ) if msg.payload.kind_of? Hash msg.payload = Hashie::Mash.new(msg.payload) end msg end |
Instance Method Details
#is_error? ⇒ Boolean
98 99 100 |
# File 'lib/zss/message.rb', line 98 def is_error? status != 200 end |
#to_frames ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/zss/message.rb', line 85 def to_frames [ identity, protocol, type, rid, address.instance_values.to_msgpack, headers.to_h.to_msgpack, status.to_s, payload.to_msgpack ] end |
#to_s ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/zss/message.rb', line 62 def to_s <<-out FRAME 0: IDENTITY : #{identity} FRAME 1: PROTOCOL : #{protocol} FRAME 2: TYPE : #{type} FRAME 3: RID : #{rid} FRAME 4: SID : #{address.sid} VERB : #{address.verb} SVERSION : #{address.sversion} FRAME 5: HEADERS : #{headers.to_h} FRAME 6: STATUS : #{status} FRAME 7: PAYLOAD : #{payload} out end |