Class: Coronet::Protocol

Inherits:
Object
  • Object
show all
Defined in:
lib/coronet/protocol.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message_format, transport_mechanism) ⇒ Protocol

Returns a new instance of Protocol.



6
7
8
9
# File 'lib/coronet/protocol.rb', line 6

def initialize(message_format, transport_mechanism)
  @message_format        = message_format
  @transport_mechanism   = transport_mechanism
end

Instance Attribute Details

#message_formatObject

Returns the value of attribute message_format.



3
4
5
# File 'lib/coronet/protocol.rb', line 3

def message_format
  @message_format
end

#transport_mechanismObject

Returns the value of attribute transport_mechanism.



4
5
6
# File 'lib/coronet/protocol.rb', line 4

def transport_mechanism
  @transport_mechanism
end

Instance Method Details

#read(io) ⇒ Object



11
12
13
14
15
# File 'lib/coronet/protocol.rb', line 11

def read(io)
  packed = @transport_mechanism.read(io)
  unpacked = @message_format.unpack(packed)
  unpacked
end

#transmit(request, host, port) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/coronet/protocol.rb', line 22

def transmit(request, host, port)
  io = @transport_mechanism.open(host,port)
  write(request, io)
  response = read(io)
  @transport_mechanism.close(io)
  response
end

#write(data, io) ⇒ Object



17
18
19
20
# File 'lib/coronet/protocol.rb', line 17

def write(data, io)
  packed = @message_format.pack(data)
  @transport_mechanism.write(packed, io)
end