Class: Bones::RPC::Protocol::Synchronize

Inherits:
ExtMessage
  • Object
show all
Defined in:
lib/bones/rpc/protocol/synchronize.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ExtMessage

#data, #datasize, #deserialize_ext_length, #ext_code, #ext_length, #ext_type, #serialize_ext_length

Methods included from BinaryHelper

included, #inspect, #receive_replies, #serialize

Constructor Details

#initialize(id, adapter) ⇒ Synchronize

Returns a new instance of Synchronize.



12
13
14
15
# File 'lib/bones/rpc/protocol/synchronize.rb', line 12

def initialize(id, adapter)
  self.id = id
  self.adapter = adapter
end

Class Method Details

.deserialize(buffer, adapter = nil) ⇒ Object



47
48
49
50
51
52
# File 'lib/bones/rpc/protocol/synchronize.rb', line 47

def self.deserialize(buffer, adapter = nil)
  message = super
  message.deserialize_id(buffer)
  message.deserialize_adapter(buffer)
  message
end

.unpack(data) ⇒ Object



54
55
56
57
58
59
# File 'lib/bones/rpc/protocol/synchronize.rb', line 54

def self.unpack(data)
  buffer = StringIO.new(data)
  id, = buffer.read(4).unpack('N')
  adapter = buffer.read
  new(id, adapter)
end

Instance Method Details

#adapter=(adapter) ⇒ Object



25
26
27
# File 'lib/bones/rpc/protocol/synchronize.rb', line 25

def adapter=(adapter)
  @adapter = Adapter.get(adapter)
end

#attach(node, future) ⇒ Object



61
62
63
# File 'lib/bones/rpc/protocol/synchronize.rb', line 61

def attach(node, future)
  node.attach(:synack, id, future)
end

#deserialize_adapter(buffer) ⇒ Object



29
30
31
# File 'lib/bones/rpc/protocol/synchronize.rb', line 29

def deserialize_adapter(buffer)
  self.adapter = buffer.read(ext_length - 5)
end

#ext_headObject



21
22
23
# File 'lib/bones/rpc/protocol/synchronize.rb', line 21

def ext_head
  0
end

#log_inspectObject



37
38
39
40
41
42
43
44
45
# File 'lib/bones/rpc/protocol/synchronize.rb', line 37

def log_inspect
  type = "SYNCHRONIZE"
  fields = []
  fields << ["%-12s", type]
  fields << ["id=%s", id]
  fields << ["adapter=%s", adapter]
  f, v = fields.transpose
  f.join(" ") % v
end

#serialize_adapter(buffer) ⇒ Object



33
34
35
# File 'lib/bones/rpc/protocol/synchronize.rb', line 33

def serialize_adapter(buffer)
  buffer << adapter.adapter_name.to_s
end