class Lignite::Message

A Message has 3 common parts:

and then a type-specific body.

Attributes

body[R]
msgid[R]
type[R]

Public Class Methods

direct_command_no_reply(body) click to toggle source
# File lib/lignite/message.rb, line 50
def self.direct_command_no_reply(body)
  new(type: 0x80, body: body)
end
direct_command_with_reply(body) click to toggle source
# File lib/lignite/message.rb, line 46
def self.direct_command_with_reply(body)
  new(type: 0x00, body: body)
end
msgid() click to toggle source
# File lib/lignite/message.rb, line 19
def self.msgid
  @msg_counter += 1
  logger.debug "MSGID #{@msg_counter}"
  @msg_counter
end
new(type:, body:) click to toggle source
# File lib/lignite/message.rb, line 27
def initialize(type:, body:)
  @msgid = self.class.msgid
  @type = type
  @body = body
end
reply_from_bytes(bytes) click to toggle source

@param bytes [ByteString] does not include the length field

# File lib/lignite/message.rb, line 55
def self.reply_from_bytes(bytes)
  msgid = unpack_u16(bytes[0..1])
  type = unpack_u8(bytes[2])
  body = bytes[3..-1]
  case type
  when 0x03               # SYSTEM_REPLY
    SystemReply.new(msgid: msgid, error: false, body: body)
  when 0x05               # SYSTEM_REPLY_ERROR
    SystemReply.new(msgid: msgid, error: true, body: body)
  when 0x02               # DIRECT_REPLY
    DirectReply.new(msgid: msgid, error: false, body: body)
  when 0x04               # DIRECT_REPLY_ERROR
    DirectReply.new(msgid: msgid, error: true, body: body)
  else
    raise format("Unexpected reply type %x", type)
  end
end
reset_msgid() click to toggle source
# File lib/lignite/message.rb, line 14
def self.reset_msgid
  @msg_counter = 0
end
system_command_no_reply(body) click to toggle source
# File lib/lignite/message.rb, line 42
def self.system_command_no_reply(body)
  new(type: 0x81, body: body)
end
system_command_with_reply(body) click to toggle source
# File lib/lignite/message.rb, line 38
def self.system_command_with_reply(body)
  new(type: 0x01, body: body)
end

Public Instance Methods

bytes() click to toggle source

not including the length

# File lib/lignite/message.rb, line 34
def bytes
  u16(@msgid) + u8(@type) + @body
end