Module: Docscribe::Server::Protocol
- Defined in:
- lib/docscribe/server.rb
Overview
JSON-line protocol helpers.
Class Method Summary collapse
-
.build_request(method, params = {}) ⇒ Hash<Symbol, Object>
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, Object>
Note:
module_function: defines #build_request (visibility: private)
Build a JSON-RPC request hash.
222 223 224 225 226 227 228 229 |
# File 'lib/docscribe/server.rb', line 222 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.
238 239 240 241 242 |
# File 'lib/docscribe/server.rb', line 238 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.
249 250 251 |
# File 'lib/docscribe/server.rb', line 249 def serialize(hash) "#{JSON.generate(hash)}\n" end |