Class: Protocol::Jsonrpc::Framer

Inherits:
Object
  • Object
show all
Defined in:
lib/protocol/jsonrpc/framer.rb

Instance Method Summary collapse

Constructor Details

#initialize(stream, frame_class: Frame) ⇒ Framer

Returns a new instance of Framer.



11
12
13
14
# File 'lib/protocol/jsonrpc/framer.rb', line 11

def initialize(stream, frame_class: Frame)
  @stream = stream
  @frame_class = frame_class
end

Instance Method Details

#closeObject

Close the stream



36
37
38
# File 'lib/protocol/jsonrpc/framer.rb', line 36

def close
  @stream.close
end

#flushObject

Flush the stream



31
32
33
# File 'lib/protocol/jsonrpc/framer.rb', line 31

def flush
  @stream.flush
end

#read_frame {|frame| ... } ⇒ Frame

Read a frame from the stream

Yields:

  • (frame)

Returns:

  • (Frame)

    The parsed frame



18
19
20
21
22
# File 'lib/protocol/jsonrpc/framer.rb', line 18

def read_frame(&block)
  frame = @frame_class.read(@stream)
  yield frame if block_given?
  frame
end

#write_frame(frame) ⇒ Object

Write a frame to the stream

Parameters:

  • frame (Frame)

    The frame to write



26
27
28
# File 'lib/protocol/jsonrpc/framer.rb', line 26

def write_frame(frame)
  frame.write(@stream)
end