Module: Docscribe::Server::Protocol
- Defined in:
- lib/docscribe/server/protocol.rb
Overview
JSON-line protocol helpers.
Class Method Summary collapse
-
.build_request(method, params = {}) ⇒ Hash<Symbol, String, Hash<Symbol, T>>
Build a JSON-RPC request hash.
-
.parse_response(line) ⇒ Hash<String, Object>??
Parse a single JSON-line response.
-
.serialize(hash) ⇒ String
Serialize a hash to a JSON line.
Class Method Details
.build_request(method, params = {}) ⇒ Hash<Symbol, String, Hash<Symbol, T>>
Note:
module_function: defines #build_request (visibility: private)
Build a JSON-RPC request hash.
18 19 20 21 22 23 24 25 |
# File 'lib/docscribe/server/protocol.rb', line 18 def build_request(method, params = {}) { jsonrpc: '2.0', id: SecureRandom.hex(8), method: method, params: params } end |
.parse_response(line) ⇒ Hash<String, Object>??
Note:
module_function: defines #parse_response (visibility: private)
Parse a single JSON-line response.
34 35 36 37 38 |
# File 'lib/docscribe/server/protocol.rb', line 34 def parse_response(line) JSON.parse(line) rescue JSON::ParserError nil end |
.serialize(hash) ⇒ String
Note:
module_function: defines #serialize (visibility: private)
Serialize a hash to a JSON line.
45 46 47 |
# File 'lib/docscribe/server/protocol.rb', line 45 def serialize(hash) "#{JSON.generate(hash)}\n" end |