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.
239 240 241 242 243 244 245 246 |
# File 'lib/docscribe/server.rb', line 239 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.
255 256 257 258 259 |
# File 'lib/docscribe/server.rb', line 255 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.
266 267 268 |
# File 'lib/docscribe/server.rb', line 266 def serialize(hash) "#{JSON.generate(hash)}\n" end |