Class: Nanite::Packet

Inherits:
Object show all
Defined in:
lib/nanite/packets.rb

Overview

Base class for all Nanite packets, knows how to dump itself to JSON

Direct Known Subclasses

Advertise, FileChunk, FileEnd, FileStart, Ping, Push, Register, Request, Result

Instance Method Summary collapse

Constructor Details

#initializePacket

Returns a new instance of Packet.

Raises:

  • (NotImplementedError)


5
6
7
# File 'lib/nanite/packets.rb', line 5

def initialize
  raise NotImplementedError.new("#{self.class.name} is an abstract class.")
end

Instance Method Details

#to_json(*a) ⇒ Object



8
9
10
11
12
13
# File 'lib/nanite/packets.rb', line 8

def to_json(*a)
  {
    'json_class'   => self.class.name,
    'data'         => instance_variables.inject({}) {|m,ivar| m[ivar.sub(/@/,'')] = instance_variable_get(ivar); m }
  }.to_json(*a)
end