Class: Protocol::Jsonrpc::Connection
- Inherits:
-
Object
- Object
- Protocol::Jsonrpc::Connection
- Defined in:
- lib/protocol/jsonrpc/connection.rb
Instance Method Summary collapse
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(framer) ⇒ Connection
constructor
Initialize a new Connection instance.
-
#read {|Protocol::Jsonrpc::Message| ... } ⇒ Protocol::Jsonrpc::Message, Protocol::Jsonrpc::Batch
Read the next message or batch of messages from the framer.
-
#read_frame {|Protocol::Jsonrpc::Frame| ... } ⇒ Protocol::Jsonrpc::Frame
Low level read a frame from the framer.
-
#write(message) ⇒ Boolean
Write a message to the framer.
-
#write_frame(frame) ⇒ Boolean
Low level write a frame to the framer.
Constructor Details
#initialize(framer) ⇒ Connection
Initialize a new Connection instance
11 12 13 |
# File 'lib/protocol/jsonrpc/connection.rb', line 11 def initialize(framer) @framer = framer end |
Instance Method Details
#close ⇒ Object
19 20 21 |
# File 'lib/protocol/jsonrpc/connection.rb', line 19 def close @framer.close end |
#flush ⇒ Object
15 16 17 |
# File 'lib/protocol/jsonrpc/connection.rb', line 15 def flush @framer.flush end |
#read {|Protocol::Jsonrpc::Message| ... } ⇒ Protocol::Jsonrpc::Message, Protocol::Jsonrpc::Batch
Read the next message or batch of messages from the framer
26 27 28 29 30 31 32 33 34 |
# File 'lib/protocol/jsonrpc/connection.rb', line 26 def read(&block) flush frame = read_frame = Message.load(frame.unpack) yield if block_given? rescue => e InvalidMessage.new(error: e) end |
#read_frame {|Protocol::Jsonrpc::Frame| ... } ⇒ Protocol::Jsonrpc::Frame
Low level read a frame from the framer
46 47 48 49 50 |
# File 'lib/protocol/jsonrpc/connection.rb', line 46 def read_frame(&) frame = @framer.read_frame yield frame if block_given? frame end |
#write(message) ⇒ Boolean
Write a message to the framer
39 40 41 |
# File 'lib/protocol/jsonrpc/connection.rb', line 39 def write() write_frame Frame.pack() end |
#write_frame(frame) ⇒ Boolean
Low level write a frame to the framer
55 56 57 |
# File 'lib/protocol/jsonrpc/connection.rb', line 55 def write_frame(frame) @framer.write_frame(frame) end |