Class: LanguageServer::Protocol::Transport::Io::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/language_server/protocol/transport/io/reader.rb

Direct Known Subclasses

Stdio::Reader

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Reader

Returns a new instance of Reader.



10
11
12
13
# File 'lib/language_server/protocol/transport/io/reader.rb', line 10

def initialize(io)
  @io = io
  io.binmode
end

Instance Method Details

#read(&block) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/language_server/protocol/transport/io/reader.rb', line 15

def read(&block)
  while buffer = io.gets("\r\n\r\n")
    content_length = buffer.match(/Content-Length: (\d+)/i)[1].to_i
    message = io.read(content_length) or raise
    request = JSON.parse(message, symbolize_names: true)
    block.call(request)
  end
end