Class: GrpcKit::Session::RecvBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/grpc_kit/session/recv_buffer.rb

Instance Method Summary collapse

Constructor Details

#initializeRecvBuffer

Returns a new instance of RecvBuffer


6
7
8
9
# File 'lib/grpc_kit/session/recv_buffer.rb', line 6

def initialize
  @buffer = +''.b
  @end = false
end

Instance Method Details

#end_readvoid

This method returns an undefined value.


43
44
45
# File 'lib/grpc_kit/session/recv_buffer.rb', line 43

def end_read
  @end = true
end

#end_read?Boolean

Returns:

  • (Boolean)

38
39
40
# File 'lib/grpc_kit/session/recv_buffer.rb', line 38

def end_read?
  @end
end

#read(size = nil, last: false) ⇒ String?

Parameters:

  • size (Integer, nil) (defaults to: nil)
  • last (Boolean)

Returns:

  • (String, nil)

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/grpc_kit/session/recv_buffer.rb', line 20

def read(size = nil, last: false)
  return nil if @buffer.empty?

  end_read if last

  if size.nil? || @buffer.bytesize < size
    buf = @buffer
    @buffer = ''.b
    buf
  else
    @buffer.freeze
    rbuf = @buffer.byteslice(0, size)
    @buffer = @buffer.byteslice(size, @buffer.bytesize)
    rbuf
  end
end

#write(data) ⇒ void

This method returns an undefined value.

Parameters:

  • data (String)

13
14
15
# File 'lib/grpc_kit/session/recv_buffer.rb', line 13

def write(data)
  @buffer << data
end