Class: Bones::RPC::Protocol::Acknowledge

Inherits:
ExtMessage
  • Object
show all
Defined in:
lib/bones/rpc/protocol/acknowledge.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, ready) ⇒ Acknowledge

Returns a new instance of Acknowledge.



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

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

Class Method Details

.deserialize(buffer, adapter = nil) ⇒ Object



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

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

.unpack(data) ⇒ Object



62
63
64
65
66
67
# File 'lib/bones/rpc/protocol/acknowledge.rb', line 62

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

Instance Method Details

#ext_headObject



22
23
24
# File 'lib/bones/rpc/protocol/acknowledge.rb', line 22

def ext_head
  1
end

#get(node) ⇒ Object



69
70
71
# File 'lib/bones/rpc/protocol/acknowledge.rb', line 69

def get(node)
  node.detach(:synack, id)
end

#log_inspectObject



45
46
47
48
49
50
51
52
53
# File 'lib/bones/rpc/protocol/acknowledge.rb', line 45

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

#readyObject



26
27
28
# File 'lib/bones/rpc/protocol/acknowledge.rb', line 26

def ready
  @ready
end

#ready=(val) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/bones/rpc/protocol/acknowledge.rb', line 30

def ready=(val)
  @ready = case val
  when 0xC2
    false
  when 0xC3
    true
  else
    !!val
  end
end

#serialize_ready(buffer) ⇒ Object



41
42
43
# File 'lib/bones/rpc/protocol/acknowledge.rb', line 41

def serialize_ready(buffer)
  buffer << [ready ? 0xC3 : 0xC2].pack('C')
end

#signal(future) ⇒ Object



73
74
75
# File 'lib/bones/rpc/protocol/acknowledge.rb', line 73

def signal(future)
  future.signal(FutureValue.new(self))
end