Class: Coronet::Protocol
- Inherits:
-
Object
- Object
- Coronet::Protocol
- Defined in:
- lib/coronet/protocol.rb
Instance Attribute Summary collapse
-
#message_format ⇒ Object
Returns the value of attribute message_format.
-
#transport_mechanism ⇒ Object
Returns the value of attribute transport_mechanism.
Instance Method Summary collapse
-
#initialize(message_format, transport_mechanism) ⇒ Protocol
constructor
A new instance of Protocol.
- #read(io) ⇒ Object
- #transmit(request, host, port) ⇒ Object
- #write(data, io) ⇒ Object
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(, transport_mechanism) @message_format = @transport_mechanism = transport_mechanism end |
Instance Attribute Details
#message_format ⇒ Object
Returns the value of attribute message_format.
3 4 5 |
# File 'lib/coronet/protocol.rb', line 3 def @message_format end |
#transport_mechanism ⇒ Object
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 |