Class: Lignite::Connection::Tap
- Inherits:
-
Lignite::Connection
- Object
- Lignite::Connection
- Lignite::Connection::Tap
- Includes:
- Bytes
- Defined in:
- lib/lignite/connection/tap.rb
Overview
An adapter that delegates to another connection and records the communication
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(conn, filename) ⇒ Tap
constructor
A new instance of Tap.
-
#receive ⇒ ByteString
A complete message.
- #send(payload) ⇒ Object
Methods included from Bytes
#bin_to_hex, #f32, #hex_to_bin, #u16, #u32, #u8, #unpack_f32, #unpack_u16, #unpack_u32, #unpack_u8
Methods inherited from Lignite::Connection
Methods included from Logger
Constructor Details
#initialize(conn, filename) ⇒ Tap
Returns a new instance of Tap.
10 11 12 13 14 15 |
# File 'lib/lignite/connection/tap.rb', line 10 def initialize(conn, filename) raise "File #{filename} exists, will not overwrite" if File.exist?(filename) @conn = conn @filename = filename @packets = [] end |
Instance Method Details
#close ⇒ Object
31 32 33 34 35 36 |
# File 'lib/lignite/connection/tap.rb', line 31 def close y = YAML.dump(@packets) File.write(@filename, y) super @conn.close end |
#receive ⇒ ByteString
Returns a complete message.
25 26 27 28 29 |
# File 'lib/lignite/connection/tap.rb', line 25 def receive s = @conn.receive @packets << { "RECV" => bin_to_hex(s) } s end |
#send(payload) ⇒ Object
18 19 20 21 22 |
# File 'lib/lignite/connection/tap.rb', line 18 def send(payload) r = @conn.send(payload) @packets << { "SEND" => bin_to_hex(payload) } r end |