Class: Lobster::Network::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/lobster/network/message.rb

Overview

Information to or from the client sent over the network. Messages can contain a JSON object for their value.

Direct Known Subclasses

ResponseMessage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, payload = nil) ⇒ Message

Creates a new message.


29
30
31
32
33
34
35
36
# File 'lib/lobster/network/message.rb', line 29

def initialize(id, name, payload = nil)
  fail ArgumentError unless id.is_a?(Fixnum)
  fail ArgumentError unless name.is_a?(String)

  @id      = id
  @name    = name.dup.freeze
  @payload = payload
end

Instance Attribute Details

#idFixnum (readonly)

Numerical ID of the message. This value increments between messages each time a new message is sent and is unique to the send or receive side of a connection.


14
15
16
# File 'lib/lobster/network/message.rb', line 14

def id
  @id
end

#nameString (readonly)

Name of the message type. This value is used to determine the action to take in response to receiving the message.


19
20
21
# File 'lib/lobster/network/message.rb', line 19

def name
  @name
end

#payload#to_json (readonly)

Any data object with meaning for the message type.


23
24
25
# File 'lib/lobster/network/message.rb', line 23

def payload
  @payload
end