Class: Neovim::MsgpackStream

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/neovim/msgpack_stream.rb

Overview

Handles serializing RPC messages to MessagePack and passing them to the event loop

Instance Method Summary collapse

Constructor Details

#initialize(event_loop) ⇒ MsgpackStream

Returns a new instance of MsgpackStream.



10
11
12
13
# File 'lib/neovim/msgpack_stream.rb', line 10

def initialize(event_loop)
  @event_loop = event_loop
  @unpacker = MessagePack::Unpacker.new
end

Instance Method Details

#run(session = nil) ⇒ void

This method returns an undefined value.

Run the event loop, yielding deserialized messages to the block.

Parameters:

  • session (Session) (defaults to: nil)

    Used for registering msgpack ext types as described by the vim_get_api_info call

See Also:



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/neovim/msgpack_stream.rb', line 33

def run(session=nil)
  register_types(session)

  @event_loop.run do |data|
    @unpacker.feed_each(data) do |msg|
      debug("received #{msg.inspect}")
      yield msg if block_given?
    end
  end
rescue => e
  fatal("got unexpected error #{e}")
  debug(e.backtrace.join("\n"))
end

#shutdownvoid

This method returns an undefined value.

Shut down the event loop.

See Also:



59
60
61
# File 'lib/neovim/msgpack_stream.rb', line 59

def shutdown
  @event_loop.shutdown
end

#stopvoid

This method returns an undefined value.

Stop the event loop.

See Also:



51
52
53
# File 'lib/neovim/msgpack_stream.rb', line 51

def stop
  @event_loop.stop
end

#write(msg) ⇒ self

Serialize an RPC message to and write it to the event loop.

Examples:

Write an RPC request

msgpack_stream.write([0, 1, :vim_strwidth, ["foobar"]])

Parameters:

  • msg (Array)

    The RPC message

Returns:

  • (self)


21
22
23
24
25
# File 'lib/neovim/msgpack_stream.rb', line 21

def write(msg)
  debug("writing #{msg.inspect}")
  @event_loop.write(MessagePack.pack(msg))
  self
end