Class: GrpcKit::Session::SendBuffer

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

Instance Method Summary collapse

Constructor Details

#initializeSendBuffer


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

def initialize
  @buffer = ''.b
  @end_write = false
  @deferred_read = false
end

Instance Method Details

#end_writevoid


26
27
28
# File 'lib/grpc_kit/session/send_buffer.rb', line 26

def end_write
  @end_write = true
end

#end_write?Boolean


31
32
33
# File 'lib/grpc_kit/session/send_buffer.rb', line 31

def end_write?
  @end_write
end

#need_resume?Boolean


21
22
23
# File 'lib/grpc_kit/session/send_buffer.rb', line 21

def need_resume?
  @deferred_read
end

#read(size = nil) ⇒ nil, ...


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/grpc_kit/session/send_buffer.rb', line 37

def read(size = nil)
  if @buffer.empty?
    if end_write?
      @deferred_read = false
      return nil # EOF
    end

    @deferred_read = true
    return DS9::ERR_DEFERRED
  end

  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, last: false) ⇒ void


15
16
17
18
# File 'lib/grpc_kit/session/send_buffer.rb', line 15

def write(data, last: false)
  end_write if last
  @buffer << data
end